jQuery find all inputs outside the form block
How to find all 开发者_运维技巧input elements that are outside the form block, using jQuery?
To select any input
elements that aren't descendants of a form
element you can use,
$('input:not(form input)')
Live Demo
Reference
All selectors are accepted inside :not(), for example: :not(div a) and :not(div,a).
You can use filter to remove elements that are within a form element. For example:
$('input').filter(function() {
return $(this).closest('form').size() === 0;
});
Maybe.. Some combo of not and child selectors? $("input:not(#myForm > input)")
$('input').not('form input')
should get the input elements that don't have form as an ancestor
It will be a bit expensive but one way to do this will be
$("input").filter(function(i,e){
return $(this).closest("form selector goes here").length==0;
});
this will return only those input elements which do not have the "form selector" as their ancestor.
精彩评论