Children () method usage instance in jquery _jquery

Source: Internet
Author: User

This example describes the use of the Children () method in jquery. Share to everyone for your reference. The specific analysis is as follows:

This method gets a collection of elements that contain all the child elements of each element in the matching element collection.
You can filter the matched child elements through an optional expression.

Note: Find () finds all the child elements, and children () gets only the first level of child elements.

Syntax structure:

Copy Code code as follows:
$ (selector). Children (expr)

Parameter list:

Parameters Describe
Expr Optional. An expression used to filter child elements

Instance code:

Example one:

Copy Code code as follows:

<! DOCTYPE html>
<meta charset= "Utf-8" >
<meta name= "Author" co ntent= "http://www.jb51.net/"/>
<title>children () function-cloud-Habitat community </title>
<style type= "Text/css" >
p{
  border:1px solid Blue
}
. children{
  border:1px solid green;
}
</style>
<script type= "Text/javascript" src= "Mytest/jquery/jquery-1.8.3.js" ></script& Gt
<script type= "Text/javascript" >
$ (document). Ready (function () {
  $ (". Father"). Children (). css ("Height", "100px");
})
</script>
<body>
<div class= "Father" >
<div Class = "Children" >
   <p> I am grandson p</p>
</div>
<p> I'm son p</p>
</d Iv>
<p> I am a brother p</p>
</body>

This method matches only one level of child elements.

Example two:

Copy Code code as follows:

<! DOCTYPE html>
<meta charset= "Utf-8" >
<meta name= "Author" content= "http://www.jb51.net/"/>
<title>children ()-cloud-dwelling community </title>
<script type= "Text/javascript" src= "Mytest/jquery/jquery-1.8.3.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ (". Father"). Children (". Children"). CSS ("Color", "red");
})
</script>
<body>
<div class= "Father" >
<div class= "Children" >
<p> I'm grandson P</p>
</div>
<p> I am the son p</p>
</div>
<p> I'm a brother p</p>
</body>

The above code sets the font color to red in a child element with a class attribute value of children.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.