Home > Article > Web Front-end > Examples of usage of find() method in jQuery
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:
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>
The above code can download the father element The border of the element with id
attributeThe 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!