admin管理员组文章数量:1312699
I have a dynamic form that I've written in rails. I want to be sure that a user can add no more than five links.
I start with two links and I have another link that allows the user to add another field. I also have a link next to the links that allows the user to remove a field, which sets a hidden field and then hides the field with slideUp();.
I want to know if there are 5 fields on the screen that the user is hoping to submit.
Here's what I'm currently using - this just counts all of the divs with that classname.
if($(".classname").length <5){
//create element dynamically
}
I want to check if "style='display: none;'" How might I do that?
I have a dynamic form that I've written in rails. I want to be sure that a user can add no more than five links.
I start with two links and I have another link that allows the user to add another field. I also have a link next to the links that allows the user to remove a field, which sets a hidden field and then hides the field with slideUp();.
I want to know if there are 5 fields on the screen that the user is hoping to submit.
Here's what I'm currently using - this just counts all of the divs with that classname.
if($(".classname").length <5){
//create element dynamically
}
I want to check if "style='display: none;'" How might I do that?
Share Improve this question edited Jun 3, 2011 at 9:15 Arun P Johny 388k68 gold badges531 silver badges532 bronze badges asked Jun 3, 2011 at 9:05 CyrusCyrus 3,7175 gold badges36 silver badges68 bronze badges 1- 1 possible duplicate of Jquery count number of hidden elements within div – Felix Kling Commented Jun 3, 2011 at 9:09
2 Answers
Reset to default 10Use the :hidden
selector:
if ($(".classname:hidden").length < 5) {
//create element dynamically
}
This will return any element with that class which is not viewable to the user. If you just want to check for display:none
, then use filter()
:
$(".classname").filter(function () {
return $(this).css("display") == "none";
});
You can try like this
$('.classname:not([style*="display: none"])').length
本文标签: javascriptHow do I count the number of hidden divs of a certain class with jqueryStack Overflow
版权声明:本文标题:javascript - How do I count the number of hidden divs of a certain class with jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741838408a2400350.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论