将类添加到父元素 [英] Add class to parent element
本文介绍了将类添加到父元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道这个问题之前已经被问过很多次了,但我找不到任何有效的工具。
我需要将一个类添加到通过我的ul自动生成的div。
I know this has been asked many times before, but I could not find anything that worked. I will need to add a class to a div that gets autogenerated over my ul.
这是我的html代码:
This is my html code:
<div class="wrapper">
<ul id="bx-pager">
<li><a><img></a></li>
<li><a><img></a></li>
</ul>
</div>
我需要为div classwrapper添加第二个类,但在尝试过之后,我不能让它工作。如果有人能够帮助我完成这个简单的任务,我会很高兴,但是告诉我如何去做。我对jQuery没有多少经验,但现在需要它。
I need to add a second class to div class "wrapper", but after what I have tried I can't get it to work. I would be nice if someone can help me out with this simple task, but showing me how to do it. I don't have much experience with jQuery, but need it now.
推荐答案
You can use the JQuery parent selector:
$('#bx-pager').parent('div').addClass('newClass');
这篇关于将类添加到父元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文