admin管理员组文章数量:1325236
I'm trying to use HTML5 valid markup here, so instead of adding to values to class I want to use the data-*="" to show/hide certain divs.
<div class="randomclass" data-chattingto="cheesecake"></div>
<div class="randomclass" data-chattingto="milkshake"></div>
<div class="randomclass" data-chattingto="cheesecake"></div>
<div class="randomclass" data-chattingto="milkshake"></div>
I can get the value of data-chattingto like so:
$("div").data("chattingto");
and I can hide/show a div with a certain class like so:
$(".randomclass").hide();
But how do I hide all divs with the data-chattingto value of cheesecake?
Thank you very much.
I'm trying to use HTML5 valid markup here, so instead of adding to values to class I want to use the data-*="" to show/hide certain divs.
<div class="randomclass" data-chattingto="cheesecake"></div>
<div class="randomclass" data-chattingto="milkshake"></div>
<div class="randomclass" data-chattingto="cheesecake"></div>
<div class="randomclass" data-chattingto="milkshake"></div>
I can get the value of data-chattingto like so:
$("div").data("chattingto");
and I can hide/show a div with a certain class like so:
$(".randomclass").hide();
But how do I hide all divs with the data-chattingto value of cheesecake?
Thank you very much.
Share Improve this question asked Aug 10, 2012 at 21:04 Seb123Seb123 4911 gold badge7 silver badges20 bronze badges2 Answers
Reset to default 10Simply use attribute-equals notation:
$('div[data-chattingto="cheesecake"]').hide();
And a JS Fiddle demo, kindly provided by CrunchyV. References:
[attribute="value"]
selector.
That would be:
$('div[data-chattingto = "cheesecake"]').show();
And
$('div[data-chattingto = "cheesecake"]').hide();
本文标签: javascriptHide or show all divs for a certain value of a data attributeStack Overflow
版权声明:本文标题:javascript - Hide or show all divs for a certain value of a data attribute - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742168212a2426223.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论