How to filter DOM elements that are either <div>s or <input>s using a single jQuery selector?
How to filter DOM elements that ar开发者_高级运维e either <div>
s or <input>
s using a single jQuery selector? For example, if I have the following HTML document:
<!DOCTYPE html ...>
<html xmlns="...">
<head>...</head>
<body>
<input value=""/>
<div></div>
<select><option value="hi">ho</option></select>
</body>
</html>
I would like to use something like $('body > ???')
to select the <input>
and the <div>
, but not the <select>
.
It's simple as $('input, div')
.
Use:
$("body > input, body > div")
$("body *").not("select").each(function() {
// code here
});
Something like that should work a treat.
See this example - http://jsfiddle.net/UeHTV/
精彩评论