I wish elements such as buttons had an automatic show/hide option based on their properties. But since they do not, I use these code examples on an event site where speakers may or may not provide their LinkedIn profile, a video of their talk, and a handout for their talk. If the button has no link, I hide it.
The tricky little bit of code I picked up in another article in this forum is “if ( ! …”—which is IF NOT. So if(!$w(‘#linkedin’).link) means if there’s not a link on the button labeled linkedin, then do the next thing.
// Hide inactive buttons (no repeater)
import wixData from ‘wix-data’;
$w.onReady( function () {
$w(“#dynamicDataset”).onReady(() => {
if (!$w(‘#linkedin’).link) {$w(“#linkedin”).hide();} //alternatively use collapse instead of hide
if (!$w(‘#video’).link) {$w(“#video”).hide();}
if (!$w(‘#handout’).link) {$w(“#handout”).hide();}
}
)
});
If you’re checking buttons in a repeater use this:
// Hide inactive buttons in repeater
import wixData from ‘wix-data’;
$w.onReady( function () {
$w(“#dataset1”).onReady(() => {
$w(“#repeater1”).onItemReady(($item, itemData, index) => {
if (!$item(‘#linkedin’).link){$item(“#linkedin”).hide();}
if (!$item(‘#video’).link){$item(“#video”).hide();}
if (!$item(‘#handout’).link){$item(“#handout”).hide();}
}
)
})
});