Home > Article > Web Front-end > Example of usage of first() method in jQuery
This article mainly introduces the usage of the first() method in jQuery. The example analyzes the function, definition and usage skills of the first() method to obtain the first element in the matching element set. Friends who need it can refer to
The examples in this article describe the usage of the first() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:
This method obtains the first element in the matching element set.
Grammar structure:
The code is as follows:
$(selector).first()
Instance code:
The code is as follows:
<!DOCTYPE html> <html> < head > <meta charset=" utf-8"> <meta name="author" content="http://www.jb51.net/" /> <title>first() 函数 -脚本之家</title> <script type="text/ javascript " src="mytest/jQuery/jquery-1.8.3.js"></script> <script type="text/javascript"> $( document ).ready(function(){ $("li").first().css("color","blue") }) </script> </head> <body> <p> <ul> <li>HTML专区</li> <li class="js">Javascript专区</li> <li>p+Css专区</li> <li>Jquery专区</li> </ul> </p> </body> </html>
The above code can set the color of the text in the first li element to blue.
The above is the detailed content of Example of usage of first() method in jQuery. For more information, please follow other related articles on the PHP Chinese website!