开发者

How to filter DOM elements that are either <div>s or <input>s using a single jQuery selector?

开发者 https://www.devze.com 2023-02-13 16:04 出处:网络
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:

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/

0

精彩评论

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