Home >>jQuery Tutorial >jQuery element + next Selector

jQuery element + next Selector

jQuery element + next Selector

jQuery element + next selector in jQuery is used to selects the "next" element of the specified "element" to be selected.

Syntax:
("element + next")

Parameter Values

Parameter Description
element It is a Required parameter and used for any valid jQuery selector
next It is a Required parameter and used to specifies the element that should be the next element of the element parameter
Here is an Example of jQuery element + next Selector:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("div + p").css("background-color", "orange");
});
</script>
</head>
<body>
<h2>Hello phptpoint !</h2>
<div style="border:1px solid black;padding:10px;">This is a div element.</div>
<p>This p element is next to a div element.</p>
<p>This is another p element.</p>
<div style="border:1px solid black;padding:10px;">
<p>This is a p element inside a div element.</p>
</div>
</body>
</html>

Output:

Hello phptpoint !

This is a div element.

This p element is next to a div element.

This is another p element.

This is a p element inside a div element.


No Sidebar ads