我选择
$("a.tp[programm='" + programm + "']");
然后我想选择它的嵌套元素span.thump并设置它的文本。我如何意识到这一点?
<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>
最佳答案
你的意思是这样吗
<a class="tp" programm="foo">blah <span class="thump">setTextOfThis</span> blah</a>
?如果是这样,请尝试
$("a.tp[programm='" + programm + "'] span.thump").text(newText);
<小时/>
编辑:关于更新,请尝试
$("a.tp[programm='" + programm + "'] + a span.thump").text(newText);
(如果包含 ... ~ a span.thump
的 <a>
不是紧邻 <span>
,则您可能需要 <a programm>
。
关于javascript - jQuery,选择嵌套元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3728226/