jQuery element + next Selector
Example
Definition and Usage
The ("element + next") selector selects the "next" element that is placed immediately after the specified "element". The "next" element must be placed right after the specified "element".
Example: If there are two <p> elements to the right of a <div> element, the syntax would be:
- $("div + p") - Selects only the first
<p>element, because it is the next element to the<div>element (the other<p>element will be ignored).
Example: If there is an <h2> element to the right of both the <div> element and the <p> element, the syntax would be:
- $("div + p") - Will not select the
<p>element, because the next element to the<div>element is the<h2>element.
Note: The two specified elements must share the same parent element.
Syntax
$("_element_ + _next_")
| Parameter | Description |
|---|---|
| element | Required. Any valid jQuery selector. |
| next | Required. Specifies the element that must be the next element to the element parameter. |
More Examples
Select the next <div> element that is adjacent to each <ul> element.
YouTip