My 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.
The rel value will be dynamically generated. So I would like to hide any div.mydiv where the 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(); is proper answer to your question. OR you can do this way as well
$('div.mydiv').not('div[rel="1"]').hide();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.