2010-09-16 77 views
0

我选择jQuery的,选择嵌套元素

$("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> 
+0

你可以发布html吗? – 2010-09-16 15:31:16

回答

3

你的意思是这样

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

+0

postet我的html代码上面,这种解决方案不起作用我已经试过 – 2010-09-16 15:34:45

+0

谢谢多数民众赞成它:) – 2010-09-16 15:38:34

+0

什么是'+'运营商在这里做?我无法在文档中找到它。 – fearofawhackplanet 2010-09-16 15:42:10

0

那么,你正在寻找的<span>不是那个孩子您正在选择标签,因此您需要遍历.parent()节点和.find()正确的孩子。

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

为什么不只是使用'兄弟姐妹()'? – fearofawhackplanet 2010-09-16 15:42:44