简体   繁体   English

Jquery - 找到同一类的所有元素,隐藏没有特定rel的div

[英]Jquery - Locating all elements of same class, hide div that does not have specific rel

My HTML: 我的HTML:

<div class="mydiv" rel="1">test one</div>
<div class="mydiv" rel="2">test two</div>
<div class="mydiv" rel="3">test three</div>
<div class="mydiv" rel="2">test three</div>

My goal is to use jQuery to hide all div elements that DO NOT have a rel of, say, 1. 我的目标是使用jQuery来隐藏所有没有 rel的div元素,比方说1。

The rel value will be dynamically generated. rel值将动态生成。 So I would like to hide any div.mydiv where the rel != 1. 所以我想隐藏任何div.mydiv,其中rel!= 1。

Any help is appreciated. 任何帮助表示赞赏。

隐藏除了一个之外具有rel值的所有div都是这样简单的:

$(".myDiv[rel!=1]").hide();
$('.mydiv').filter(function() {
    return $(this).attr('rel') != 1;
}).hide();

$(".myDiv[rel!=1]").hide(); $( “myDiv [!相对= 1]”)隐藏(); is proper answer to your question. 是你的问题的正确答案。 OR you can do this way as well 或者你也可以这样做

$('div.mydiv').not('div[rel="1"]').hide();

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

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