سؤال

function NavMenu() {
    $(function() {                       
      $(".toggle-topbar").click(function() {
        $(".top-bar").addClass("expanded"); 
      });
    });
}

This function allows a Menu Button to expand a drop down for when running on a mobile/tablet device, ive so far got it this far, which expands the drop down, however how do i go about removing the class when i then click the option again?

Many Thanks

هل كانت مفيدة؟

المحلول

You can use toggleClass()

$(".top-bar").toggleClass("expanded"); 
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top