Hello friends,
Today we learn how to check next sibling of an element using jQuery. In jQuery, next() method is used to match the immediate sibling of an element.
Syntax:
.next( [selector ] )
selector is the optional parameter which is an expression to match the element.
Let's take an example to understand the .next() method. Suppose we have an element span whose next we want to display a text. For this you need to write the code as follow:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".test1").next().text('This is the sibling ');
});
</script>
</head>
<body class="siblings">
<span class="test1">span</span>
<span></span>
</body>
</html>
0 Comment(s)