locked
Javascript dropdown for mobile-nav problem RRS feed

  • Question

  • User-118859203 posted

    Hi all,

    During creating dropdown menu to open and collapse int the "mobile-nav" I am facing problem. Dropdown menu is not working.

    My JavaScript code is here

    function mobNav() {
      $('.mobile-nav-toggle').on('click', function() {
        var status = $(this).hasClass('is-open');
        if (status) {
          $('.mobile-nav-toggle, .mobile-nav').removeClass('is-open');
        } else {
          $('.mobile-nav-toggle, .mobile-nav').addClass('is-open');
        }
      });
    }

    Anyone can help me please. Thanks for your help! 

    Friday, January 11, 2019 2:07 AM

Answers

  • User-552477072 posted

    Hi there,

    You need to add link to jQuery script.
    Also, Delete declaration function mobNav() { and it closing braket }.

    Should be working fine as

    $('.mobile-nav-toggle').on('click', function() {
    var status = $(this).hasClass('is-open');
    if (status) {
    $('.mobile-nav-toggle, .mobile-nav').removeClass('is-open');
    } else {
    $('.mobile-nav-toggle, .mobile-nav').addClass('is-open');
    }
    });


    Pls don't forget to mark as answer if it helps you. Thanks!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 11, 2019 2:31 AM

All replies

  • User-552477072 posted

    Hi there,

    You need to add link to jQuery script.
    Also, Delete declaration function mobNav() { and it closing braket }.

    Should be working fine as

    $('.mobile-nav-toggle').on('click', function() {
    var status = $(this).hasClass('is-open');
    if (status) {
    $('.mobile-nav-toggle, .mobile-nav').removeClass('is-open');
    } else {
    $('.mobile-nav-toggle, .mobile-nav').addClass('is-open');
    }
    });


    Pls don't forget to mark as answer if it helps you. Thanks!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 11, 2019 2:31 AM
  • User839733648 posted

    Hi kamalhussain,

    According to your description and could, I'm sorry that I could not reproduce your issue successfully.

    How is your html page designed? 

    If possible, please provide more details like related html code to class mobile-nav-toggle and mobile-nav.

    This will be easier for us to help with you.

    Best Regards,

    Jenifer

    Friday, January 11, 2019 10:02 AM
  • User-118859203 posted

    Thanks rubaiyat2009, that was the issue.

    Saturday, January 12, 2019 8:24 AM