Home  >  Article  >  Web Front-end  >  jQuery traversal next(), nextAll() method usage examples_jquery

jQuery traversal next(), nextAll() method usage examples_jquery

WBOY
WBOYOriginal
2016-05-16 16:32:041515browse

jquery traversal: next() and nextAll() methods. Examples are as follows:

Copy code The code is as follows:








Hello, Beauty

hello,world

Beauty, give me a kiss

I am p tag


I am handsome, I have pictures and the truth

I am also a p tag



Description:

(1) next() method: refers to obtaining the adjacent sibling elements of the matching element (i.e. the next sibling element). Note that the sibling elements are not elements with the same label, but refer to the closed next sibling element of the element. An element, such as "

Beauty, give me a kiss
" in the example, the next element after the div is closed is

.

(2) If next() adds a parameter, that is, next("div"), if the next adjacent element is not a div, it will be empty, that is, it must be adjacent.

(3) nextAll() method: refers to obtaining all sibling elements after the matching element. It can also add parameters, nextAll("p") or nextAll("div"), etc.

(4) Something strange is that if it is this code:

Copy code The code is as follows:

$("div").click(function(){alert($(this).nextAll("div").html());});

It does not get all the html content, but only the html content of the next sibling element. ? ? ? Doubt

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn