开发者

jQuery - How to hide an element that is not contain the specific class

开发者 https://www.devze.com 2023-03-19 08:00 出处:网络
Suppose I have the html code below, I want to ONLY display the \"p\" element with class=\"go-1\", it is not good to write the statement to hide the element with class=\"2\", class=\"3\", class=\"100\"

Suppose I have the html code below, I want to ONLY display the "p" element with class="go-1", it is not good to write the statement to hide the element with class="2", class="3", class="100"... how can I write it in a smart way?

The statement can be say as "if "p" class not equal to "go-1" then hide it"

Thanks

<p class="go-1"></p>
<p class="go-2"></p>
<p class="go-3"></p>
...
<p class="go-100"></p>
<p class="go-1"></p>
<p class="go-2"></p>
<p class="go-3"></p>
...
<p class="go-100"></p>
<p class="go-1"></p>
<p class="go-2"></p>
<p class="go-3"></p>
...
<p class="g开发者_如何转开发o-100"></p>


Just use :not():

$('p:not(.go-1)').hide();
0

精彩评论

暂无评论...
验证码 换一张
取 消