DarkLeafyGreen
DarkLeafyGreen

Reputation: 70406

jQuery, Select nested element

I select

$("a.tp[programm='" + programm + "']");

then I want to select its nested element span.thump and set the text of it. How do i realize that?

<h4><a programm="74" class="tp" href="#"><img src="/images/tuo.png"></a><a href="">
<img width="180" height="40" src="/images/kauf_default.png"><br>test 
<span class="thump">1</span><img src="/images/ilike.png"></a></h4>

Upvotes: 0

Views: 2049

Answers (2)

kennytm
kennytm

Reputation: 523214

Do you mean something like

<a class="tp" programm="foo">blah <span class="thump">setTextOfThis</span> blah</a>

? If so, try

$("a.tp[programm='" + programm + "'] span.thump").text(newText);

Edit: Regarding the update, try

$("a.tp[programm='" + programm + "'] + a span.thump").text(newText);

(You may want ... ~ a span.thump if the <a> containing that <span> is not immediately next to that <a programm>.

Upvotes: 3

gnarf
gnarf

Reputation: 106332

Well, the <span> you are looking for is not a child of that <a> tag you are selecting, so you will need to traverse to the .parent() node and .find() the correct child.

$("a.tp[programm='" + programm + "']").parent().find('.thump');

Upvotes: 0

Related Questions