2013-10-07 73 views
-2

我有这样的结构HTMLJQuery的AddClass子元素

<ul class="footer_column"> 
    <li id="doc-22"><a href="/abc/index.php?id=22" title="wind blades coupling system" ><span>wind blades coupling system</span></a></li> 
    <li id="doc-23"><a href="/abc/index.php?id=23" title="expandable bolt" ><span>expandable bolt</span></a></li> 
    <li id="doc-24"><a href="/abc/index.php?id=24" title="security screw" ><span>security screw</span></a></li> 
    <li id="doc-25"><a href="/abc/index.php?id=25" title="TH preload system " ><span>th</span></a></li> 
</ul> 

我需要addClass到<li id="doc-25"><a><span class="notranslate">th</span></a>

+1

$( “DOC-25”).addCla ss(“myClass yourClass”); –

+0

我想这个问题还不清楚。真的不能得到OP OP想要? –

+0

$(“#doc-25 a span”).addClass(“notranslate”) – Speedy

回答

1

它不清楚。我假设你想添加类到span。因此,你可以使用.find()

$('li #doc-25').find('span').addClass('notranslate'); 
1

添加这一点,并尝试如果id是静态的,并将继续同...

$("#doc-25").addClass("myClass yourClass"); 
+2

您在选择器中缺少'#' – Satpal

1

尝试

$('#doc-25').find('span').addClass('notranslate'); 

$('#doc-25 span').addClass('notranslate'); 

$("#doc-25").children('a').children('span').addClass("class_to_add"); 

$("#doc-25 > a > span").addClass("class_to_add"); 

参考

.find()

.addClass()

.children()