JQuery AddClass to sub element



我有这个结构html

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

我需要将类添加到<li id="doc-25"><a><span class="notranslate">th</span></a>

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

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

添加这个并尝试id是否是静态的并且保持不变...

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

尝试

$('#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()

.儿童()

最新更新