简体   繁体   English

当页面上存在另一个元素时隐藏元素

[英]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:如果具有 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.我想实现是通过函数还是.css,都没有关系。

Just do it with JavaScript.只需使用 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 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM