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?
假设我有下面的html代码,我想只显示带有class =“go-1”的“p”元素,编写语句以隐藏class =“2”的元素是不好的,class =“3 “,class =”100“......我怎么能以聪明的方式写出来?
The statement can be say as "if "p" class not equal to "go-1" then hide it"
Thanks
该陈述可以说是“if”p“类不等于”go-1“然后隐藏它”谢谢
<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="go-100"></p>
1 个解决方案
#1
27
Just use :not()
:
只需使用:not():
$('p:not(.go-1)').hide();
#1
27
Just use :not()
:
只需使用:not():
$('p:not(.go-1)').hide();