繁体   English   中英

隐藏 DIV 如果它有一个带有特定文本的 P

[英]Hide DIV if it has a P with specific text

寻找一些帮助,我试图隐藏一个 DIV,如果它包含一个带有特定文本或类的 P,哪个更容易。

就我所知,我可以隐藏 P 但我需要用“即将发生的事件”类隐藏整个 div,这样 H3 就不会显示。

我遇到的一个问题是它不能是 jquery,纯 Javascript。

谢谢!

 let filteredOut = ['Carousel contents not found!']; Array.from(document.querySelectorAll("div.upcoming-events p")).forEach((elm) => { if(filteredOut.includes(elm.textContent.trim())) { elm.style.display = "none"; } })
 #carousel-97826 .slick-prev:before, #carousel-97826 .slick-next:before { color: !important; } #carousel-97826 .slick-slide { margin: 2px ; } #carousel-97826 .rpc-title { color: ; } #carousel-97826 .rpc-content { color: ; } #carousel-97826 .rpc-date { background-color: ; } #carousel-97826 .rpc-date { color: ; } #carousel-97826 .rpc-overlay { background-color: ; } #carousel-97826 .carousel-style9 { border-top-color: ; } #carousel-97826 .carousel-style9 .button:before { background-color: ; } #carousel-97826 .rpc-box { box-shadow: ; } #carousel-97826 .rpc-bg { background-color: ; } #carousel-97826 .rpc-title-bg { background-color: ; } #carousel-97826 .fixed-height-image { height: ; } #carousel-97826 .slick-next:before { content: '\\ \\f0a9 '; } #carousel-97826 .slick-prev:before { content: '\\ \\f0a8'; } #carousel-97826 .rpc-title { font-family: ; } #carousel-97826 .rpc-title { font-size: ; } #carousel-97826 .rpc-content { font-family: ; } #carousel-97826 .rpc-content { font-size: ; }
 <div class="upcoming-events" style="width: 250px; margin: 0 auto; text-align: center;"> <h3 style="text-align: center;">Highlighted Events</h3> <p>Carousel contents not found!</p> </div>

您可以在 if 条件中使用 HTML DOM parentNode 属性。

elm.parentNode.style.visibility = "hidden";

暂无
暂无

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

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