当我做 $('ul.latestnews ul li').parent().prev().text());
我找回了目标li的内容。 (在这个例子中是word1或word2)。向孩子添加班级
但是当我做
$('ul.latestnews ul li').addClass($(this).parent().prev().text());
它不添加类。当我在最后一个语句上做一个console.log时,它只是返回所有我想要添加类的li。
我所试图做的是这样的:
<ul class="latestnews">
<li>word1</li>
<ul>
<li>my class should become word1</li>
<li>my class should become word1</li>
</ul>
<li>word2</li>
<ul>
<li>my class must become word2</li>
</ul>
</ul>
哪儿我去错了吗?
什么是'this' ..? –
@Rob。窗口,我猜... – gdoron
是不是HTML无效? –