Child Selector (“parent > child”)
child selector
version added: 1.0jQuery('parent > child')
- parent
- 任何有效的選擇器。
- child
- 一個(gè)用來(lái)篩選子元素的選擇器。
描述: 選擇所有通過(guò)“parent”給定的元素直接子元素,該子元素“child”給定。
像一個(gè)CSS選擇器,這個(gè)子組合器被Safari, Firefox, Opera, Chrome, 和 Internet Explorer 7 及以上版本等現(xiàn)代瀏覽器支持,但尤其不被Internet Explorer6及以下版本支持。然而在jQuery中,這個(gè)選擇器(與其他所有選擇器)能在所有支持的瀏覽器中工作,包括IE6。
這個(gè)子組合器(E > F)可以被認(rèn)為是作為后代組合子(E F)不同,更具體的形式是它只會(huì)選擇第一級(jí)的后代。
Example:
Places a border around all list items that are children of <ul class="topnav"> .
<!DOCTYPE html>
<html>
<head>
<style>
body { font-size:14px; }
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<ul class="topnav">
<li>Item 1</li>
<li>Item 2
<ul><li>Nested item 1</li><li>Nested item 2</li><li>Nested item 3</li></ul>
</li>
<li>Item 3</li>
</ul>
<script>$("ul.topnav > li").css("border", "3px double red");</script>
</body>
</html>