child"), Jquery官方教程,Jquery官网文档,Jquery快速入门,Jquery入门指南" />

Child selector ("parent > child")

Child Selector (“parent > child”)

child selector

Description: Selects all direct child elements specified by "child" of elements specified by "parent".

  • version added: 1.0jQuery( "parent > child" )

    parent: Any valid selector.

    child: A selector to filter the child elements.

The child combinator (E > F) can be thought of as a more specific form of the descendant combinator (E F) in that it selects only first-level descendants.

Example:

Places a border around all list items that are children of <ul class="topnav"> .

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>child demo</title>
  <style>
  body {
    font-size: 14px;
  }
  	</style>
  <script src="https://code.jquery.com/jquery-1.10.2.js" rel="external nofollow" ></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>

Demo:

© The jQuery Foundation and other contributors
Licensed under the MIT License.
https://api.jquery.com/child-selector

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部