Marko I.
Marko I.

Reputation: 562

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.

Upvotes: 1

Views: 100

Answers (1)

Colin Chadwick
Colin Chadwick

Reputation: 146

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 
}

Upvotes: 1

Related Questions