# Hide Button on Dynamic Page When Field Is Empty

**URL:** <https://forum.wixstudio.com/t/hide-button-on-dynamic-page-when-field-is-empty/27740>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [January 29, 2018, 4:51pm UTC](https://forum.wixstudio.com/t/hide-button-on-dynamic-page-when-field-is-empty/27740 "2018-01-29T16:51:57Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Kenneth\_Herskind](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/kenneth_herskind/32/99925_2.png) [@Kenneth\_Herskind](https://forum.wixstudio.com/u/Kenneth_Herskind)\
**Post date:** [March 27, 2025, 12:43am UTC](https://forum.wixstudio.com/t/hide-button-on-dynamic-page-when-field-is-empty/27740/7 "2025-03-27T00:43:12Z")

</div>

> [@derek38500](#):
>
> ```javascript
> $w.onReady(function () {
> 
> $w("#dynamicDataset").onReady(() => {
>         
> $w("#dynamicDataset").getCurrentItem();
> 
> if ($w('#button').link == '') {
> $w('#button').hide();
> }
>                 
> });
> 
> });
> 
> ```

BTW, noticed that this code only works for the buttons. If you have other elements, image for example, I found this code works better for images:

> [@How to hide a section on a dynamic item page when a specific CMS field is blank](https://forum.wixstudio.com/t/how-to-hide-a-section-on-a-dynamic-item-page-when-a-specific-cms-field-is-blank/60241/13):
>
> I use the below example all the time. Note the exclamation mark before currentItem, this means ‘if empty’. Replace: #yourDatasetID with the ID of your dynamic page dataset databaseFeildID with the field ID in the CMS you want to check #itemToHideID with ID of the page item you wish to hide const currentItem = $w('#yourDatasetID').getCurrentItem(); $w.onReady(function () { if (!currentItem.databaseFeildID) { $w("#itemToHideID").collapse(); } });

Replace:  
#yourDatasetID with the ID of your dynamic page dataset  
databaseFeildID with the field ID in the CMS you want to check  
#itemToHideID with ID of the page item you wish to hide

const currentItem = $w(‘#yourDatasetID’).getCurrentItem();

$w.onReady(function () {  
if (!currentItem.databaseFeildID) { $w(“#itemToHideID”).collapse(); }  
});

---

_[View the full topic](https://forum.wixstudio.com/t/hide-button-on-dynamic-page-when-field-is-empty/27740)._
