How to remove component that is empty on dynamic page?

Hello,

Anybody got a solution? I have successfully managed to collapse 3 components using the code written here, populated with different field keys and IDs for each element of course. But when I try to collapse a YouTube video on a dataset item that has an empty URL field it does not work. Any help?

$w.onReady(() => {
    $w("#dataset1").onReady(() => {
 // Gets the current item properties and stores them in a variable called item
 const item = $w("#dataset1").getCurrentItem();
 // Checks if the current item has a value in the "video" field
 if (!item.theConceptText) {
 // Collapses the video player if there is no value for "video"
            $w("#text51").collapse();
        }
    });
});

Thanks for your time,
Georgios