views:

43

answers:

2

Hi,

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>
+2  A: 

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>.

KennyTM
postet my html code above, this solution does not work I tried already
ArtWorkAD
thanks thats it:)
ArtWorkAD
what is the `+` operator doing here? I couldn't find it in the documentation.
fearofawhackplanet
the + is just concatanating the strings to build the selector. programm is a variable.
Patricia
@fear: http://api.jquery.com/next-adjacent-Selector/.
KennyTM
A: 

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');
gnarf
why not just use `siblings()` ?
fearofawhackplanet