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