Home Web Front-end JS Tutorial Examples of usage of find() method in jQuery

Examples of usage of find() method in jQuery

Jun 30, 2017 pm 02:06 PM
find jquery Example

This article mainly introduces the usage of the find() method in jQuery. The function and definition of the find() method are analyzed with examples, as well as the usage skills of obtaining descendant elements of matching elements. Friends in need can refer to it

The example in this article describes the usage of find() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:

This method obtains the child elements of all elements in the matching element collection and deletes them through the selector, jQuery object or element.
The find() method is a good way to get descendant elements of the matching element.

Note: children() only obtains one-level child elements, while find() will find all child elements.

Grammar structure one:

The code is as follows:

$(selector).find(expr)

Parameter list:

Example code:

The code is as follows:

<!DOCTYPE html> 
<html> 
<head> 
<meta charset=" utf-8"> 
<meta name="author" content="http://www.jb51.net/" /> 
<title>children()函数-脚本之家</title> 
<script type="text/
javascript
" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript"> 
$(
document
).ready(function(){ 
  $(".father").find("p").css("color","red"); 
}) 
</script>  
</head> 
<body> 
<p class="father"> 
<p class="children"> 
   <p>我是孙子p</p> 
</p> 
<p>我是儿子p</p> 
</p> 
<p>我是兄弟p</p> 
</body> 
</html>
Copy after login

The above code can set the font color of all p elements under the father element to red.

Grammar structure two:

The code is as follows:

$(selector).find(element)

Yes Finds the specified element below the matching element.

Parameter list:

##Parameter Description
expr ##String value, define filter Expression .
##Parameter Description
element##DOM object or jQuery object used to match the element.
Example code:

The code is as follows:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.jb51.net/" />
<title>find()函数-脚本之家</title>
<style type="text/css">
.father{
  height:200px;
  width:200px;
  border:1px solid blue;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $(".father").find(document.getElementById("myp")).css("border","1px solid red");
})
</script>
</head>
<body>
<p class="father">
  <p class="children">
    <p id="myp">我是孙子p</p>
  </p>
  <p>我是儿子p</p>
</p>
<p>我是兄弟p</p>
</body>
</html>
Copy after login

The above code can download the father element The border of the element with id

attribute

value myp is set to one pixel red.

The above is the detailed content of Examples of usage of find() method in jQuery. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use PUT request method in jQuery? How to use PUT request method in jQuery? Feb 28, 2024 pm 03:12 PM

How to use PUT request method in jQuery?

How to remove the height attribute of an element with jQuery? How to remove the height attribute of an element with jQuery? Feb 28, 2024 am 08:39 AM

How to remove the height attribute of an element with jQuery?

jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

jQuery Tips: Quickly modify the text of all a tags on the page

OPPO Find X7 is a masterpiece! Capture your every moment with images OPPO Find X7 is a masterpiece! Capture your every moment with images Aug 07, 2024 pm 07:19 PM

OPPO Find X7 is a masterpiece! Capture your every moment with images

OPPO Find X8 Ultra core configuration exposed! Snapdragon 8 Gen4+ Extra Large Battery OPPO Find X8 Ultra core configuration exposed! Snapdragon 8 Gen4+ Extra Large Battery Aug 22, 2024 pm 06:54 PM

OPPO Find X8 Ultra core configuration exposed! Snapdragon 8 Gen4+ Extra Large Battery

Use jQuery to modify the text content of all a tags Use jQuery to modify the text content of all a tags Feb 28, 2024 pm 05:42 PM

Use jQuery to modify the text content of all a tags

The relationship between the number of Oracle instances and database performance The relationship between the number of Oracle instances and database performance Mar 08, 2024 am 09:27 AM

The relationship between the number of Oracle instances and database performance

Understand the role and application scenarios of eq in jQuery Understand the role and application scenarios of eq in jQuery Feb 28, 2024 pm 01:15 PM

Understand the role and application scenarios of eq in jQuery

See all articles