jQuery element + nextSelector

jQuery 选择器jQuery Selector

Examples

Select the next <p> element adjacent to each <div> element:

$("div + p")

Try it »

Definition and Usage

The ("element + next") selector selects the "next" element of the specified element "element". The "next" element must be placed to the right of the specified element "element".

Example: If there are two <p> elements to the right of a <div> element, the syntax is as follows:

  • $("div + p")- Only the first <p> element is selected, because it is the next element of the <div> element (the other <p> element will be ignored)

Example: If there is an <h2> element to the right of the <div> element and the <p> element, the syntax is as follows:

  • $("div + p")- The <p> element will not be selected, because the next element of the <div> element is the <h2> element

Note:The two specified elements share the same parent element.


Syntax

("element + next")

Parameter Description
element Required. Any valid jQuery selector.
next Required. Specifies the element, must beelementof the parameternextelement.


实例

Try it - Examples

Select the next <div> element adjacent to each <ul> element
How to select the next <div> element adjacent to each <ul> element.


jQuery 选择器jQuery Selector

Other Extensions