Skip to content
Advertisement

Add class to parent element

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.

This is my html code:

<div class="wrapper">
    <ul id="bx-pager">
       <li><a><img></a></li>
       <li><a><img></a></li>
    </ul>
</div>

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.

Advertisement

Answer

You can use the JQuery parent selector:

$('#bx-pager').parent('div').addClass('newClass');
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement