Find the first tag after a class name and change it with jquery

0

I would like to identify the first class='active' in my html and after adding a value in the class of element <ul> next, but only of the first element <ul>

My HTML

    <aside class="navigation">
            <nav>
                <ul class="nav teste-nav">
                    <li class="active">     //AQui primeiro active
                        <a href="#categoria1" data-toggle="collapse" aria-expanded="false">
                            Cat. 01<span class="sub-nav-icon"> <i class="stroke-arrow"></i> </span>
                        </a>
//mudar essa ul
                        <ul id="categoria1" class="nav nav-second collapse in">
                            <li><a href="#"> Países</a></li>
                            <li class="active"><a href="#"> Estados</a></li>
                            <li><a href="#"> Cidades</a></li>
                            <li><a href="#"> Bairros</a></li>
                            <li><a href="#"> Logradouros</a></li>
                        </ul>
                    </li>
                    <li class="">
                        <a href="#categoria2" data-toggle="collapse" aria-expanded="false">
                            Cat 02<span class="sub-nav-icon"> <i class="stroke-arrow"></i> </span>
                        </a>
                        <ul id="categoria2" class="nav nav-second collapse">
                            <li><a href="#"> Países</a></li>
                            <li><a href="#> Estados</a></li>
                            <li><a href="#"> Cidades</a></li>
                            <li><a href="#"> Bairros</a></li>
                            <li><a href="#"> Logradouros</a></li>
                        </ul>
                    </li>
                </ul>
            </nav>
        </aside>

I would like with jquery to identify the first li with class active and when identifying to change the class from a href to nav nav-second collapse in

I'm trying to do this:

$(".active").after(function () {
     $("ul").toggleClass("in");
});

but it puts 'in' on all ul ul.

I also tried:

$("ul:first").toggleClass("in");

or

$("ul").fir.toggleClass("in");

But do not add in.

    
asked by anonymous 26.10.2016 / 18:58

1 answer

1

Try this:

$(".active").after(function () {
    $(this).find("ul:first").toggleClass("in");
});

You can do direct too:

$('.active ul:first').toggleClass('in');
    
26.10.2016 / 19:06