Its_bubbadog Its_bubbadog - 3 months ago 13
CSS Question

jQuery toggleClass() not working

I was just wondering how I would go about making something toggle on and off in jQuery. What I want to do is have the download dropdown menu toggle when somebody clicks on "download" The class works with the hover effect, but won't work for the click effect for some reason! Any help would be awesome!

JSFiddle: https://jsfiddle.net/830f119e/1/

<div class="navigation">
<div class="nav">
<div class="logo">
ZeteticRSPS
</div>
<ul>
<li><a href="#">Forum</a></li>
<li><a href="#">Store</a></li>
<li class="download-dropdown">
<a href="#" class="drop-btn">Download</a><i class="fa fa-caret-right nav-icon" aria-hidden="true"></i>
<div class="dropdown-content">
<a href="#">Mediafire</a>
<a href="#">Direct Download</a>
</div>
</li>
<li><a href="#">Vote</a></li>
</ul>
</div>




jQuery:

$( "download-dropdown" ).click(function() {
$( this ).toggleClass( "download-dropdown-toggle" );
});

Answer

Try following code.

$( ".download-dropdown a" ).click(function() {
  $( this ).parent().find('.dropdown-content').slideToggle();
});

Working Fiddle.

You haven't chosen jQuery in JSFiddle.

Comments