Home > Web Front-end > JS Tutorial > body text

Detailed explanation of the usage of the traversal function siblings() in jquery

巴扎黑
Release: 2017-06-22 14:08:23
Original
1500 people have browsed it

This article mainly introduces the usage of jquery traversal function siblings(), and analyzes the related techniques of jquery's siblings function for element traversal in detail in the form of examples. Friends in need can refer to this article

The example describes the usage of jquery traversal function siblings(). Share it with everyone for your reference, the details are as follows:

siblings([expr])

Get the set of all sibling elements of each element in the set of all matching elements. Return the set of matching elements


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
 <script src="jquery.js"></script>
 <script>
 $(document).ready(function(){
  var len = $(".hilite").siblings().css("color", "red").length;
  $("b").text(len);
 });
 </script>
 <style>
 ul { float:left; margin:5px; font-size:16px; font-weight:bold; }
 p { color:blue; margin:10px 20px; font-size:16px; padding:5px;
   font-weight:bolder; }
 .hilite { background:yellow; }
</style>
</head>
<body>
 <ul>
  <li>One</li>
  <li>Two</li>
  <li class="hilite">Three</li>
  <li>Four</li>
 </ul>
 <ul>
  <li>Five</li>
  <li>Six</li>
  <li>Seven</li>
 </ul>
 <ul>
  <li>Eight</li>
  <li class="hilite">Nine</li>
  <li>Ten</li>
  <li class="hilite">Eleven</li>
 </ul>
 <p>Unique siblings: <b></b></p>
</body>
</html>
Copy after login

Copy code The code is as follows:

$(".hilite").siblings()

Will get a collection of all sibling elements containing the special style 'hilite' element. The following is the set of matching elements


<li>One</li>
<li>Two</li>
<li>Four</li>
<li>Eight</li>
<li class="hilite">Nine</li>
<li>Ten</li>
<li class="hilite">Eleven</li>
Copy after login

The above is the detailed content of Detailed explanation of the usage of the traversal function siblings() in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template