Collapse/Expand elements in a dynamic page if a field in a database is empty

Hi there, I am using this code and it seems to work perfectly, might anyone want to give it ago. Hope this helps.

$w(“#yourDataset”).onReady( () => {
let item = $w(“#yourDataset”).getCurrentItem();
if (item[“cafeonline”] === undefined) {
$w(“#button51”).hide();
$w(“#button51”).collapse();//set height to 0
} else {
$w(“#button51”).show() ;
}
} );