Hello Readers,
If we want to fetch or return the all sibling elements of the selected or matched elements then we use the .siblings() method in jQuery.
It is the elements that belong to the same parent.
Syntax :
selector.siblings( [selector] )
Parameters :
selector - selector is a optional parameter which is used to filter the sibling elements.
Below is the Code Example of siblings method :
<html>
<head>
<title>The jQuery Example</title>
<script type = "text/javascript"
src = "http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type = "text/javascript" language = "javascript">
$(document).ready(function(){
$("p").siblings('.selected').addClass("hilight");
});
</script>
<style>
.hilight { background:yellow; }
</style>
</head>
<body>
<div><span>Hello</span></div>
<p class = "selected">Hello Again</p>
<p>And Again</p>
</body>
</html>
In the above Code, we use the optional parameter class (.selected) and addClass (hilight) on it.
0 Comment(s)