Search code examples
jquerytoggleclass

jQuery toggleClass not working in my example


ToggleClass seems to not do anything on my site and i can't figure out why. I wrote a short example to make it easier for me but it still doesn't work... I think I got the syntax right...

http://jsfiddle.net/eakzrqqg/

<!--html-->

<div class="arrow">
    <a href=#>menu<br>▼</a>
</div>

<ul class="header-links">
        <li><a href="">link1</a></li>
        <li><a href="">link2</a></li>
        <li><a href="">link3</a></li>    
</ul>

<!--css-->

.bg{
       background: black;  
    }

<!--js-->

$(".arrow a").click(

function () {
$(".header-links").toggleClass(".bg");
}

);

Solution

  • $(".header-links").toggleClass("bg"); //Just remove '.' in 'bg' class name here.