questions

Hide element when another element is present on the page

Rate this post

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.

 

✔️Solution:

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 
}

Leave a Reply

Your email address will not be published.

Back to top button