Home  >  Article  >  Web Front-end  >  Example of usage of first() method in jQuery

Example of usage of first() method in jQuery

巴扎黑
巴扎黑Original
2017-06-22 14:55:551905browse

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!

Statement:
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