Its_bubbadog Its_bubbadog - 1 year ago 104
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!


<div class="navigation">
<div class="nav">
<div class="logo">
<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>
<li><a href="#">Vote</a></li>


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

Answer Source

Try following code.

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

Working Fiddle.

You haven't chosen jQuery in JSFiddle.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download