In jquery, match the first next element

I have a href tag and there is a tag next to it . I want to add new text between the bold tag.

<a href=""></a> <b>old text</b>

So, in my click handler, how can I get a link to the text between the bold tag?

I know that there is $ (this + b), but how can I make sure that it receives only the first and not ALL the following elements (for example, in the jquery example).

+3
source share
4 answers

Get b-tag with

$(this).next();

Get text inside tag b with:

$(this).next().text();

And set the text inside the b tag:

$(this).next().text("Something new");
+7
source

, , (). . , . , , , "a" "b". ", ", :

$('a').nextAll('b:first')

, ( ).

+22

:

$(this).siblings(":first").text("Something new");
+5

, , , (#myid,.myclass ..) (: visible,: first,: odd ..). )

.parent()
.sibling()
.children()
.next()
.prev()
+2

Source: https://habr.com/ru/post/1703429/


All Articles