开发者

jQuery xPath selector, &&

开发者 https://www.devze.com 2022-12-19 17:36 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号