jQuery xPath selector, &&
I'm using jQuery to run through all the inputs within a section that I have set from hidden to show, and add required calsses, so as to catch the validation.
$("#" + dependant).find("input[type!='radio']").addClass('required');
Works fine, but I also want to exclude the submits. In normal开发者_运维知识库 xPath I would;
input[type!='radio' and type!='submit']
I acheived a work around using .each() and an additional IF;
$("#" + dependant).find("input[type!='radio']").each(function()
{
if ($(this).attr(type) != 'submit')
{
$(this).addClass('required')
}
});
But it strikes me there must be an easier, cleaner way of combining contraints....
See Traversing and Selectors in the jQuery docs.
$("#" + dependant).find(":input").not(':radio').not(':submit').addClass('required');
- http://api.jquery.com/category/selectors/
- http://api.jquery.com/category/traversing/
You can do:
$("#" + dependant).find("input[type!='radio'][type!='submit']").addClass('required');
See multiple attribute selector:
Description: Matches elements that match all of the specified attribute filters.
精彩评论