Skip to content
Advertisement

Hide element when another element is present on the page

I want to hide an element if one element is already present on the page.

If element with the id:

#wcfmmp_store_about

is present on the page, then hide following element:

.left_sidebar.widget-area.sidebar

I want to achieve is either through a function or .css, it doesn’t matter.

Advertisement

Answer

Just do it with JavaScript.

var element = document.getElementById('wcfmmp_store_about');

if (typeof(element) != 'undefined' && element != null)
{
 document.querySelector('.left_sidebar').classList.add("sidebar_hidden");
} else {
 document.querySelector('.left_sidebar').classList.remove("sidebar_hidden");
}
.left_sidebar.sidebar_hidden {
  display: none 
}
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement