Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9071109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:50:06+00:00 2026-06-16T17:50:06+00:00

I am (very) new to jQuery so please be gentle but I cannot seem

  • 0

I am (very) new to jQuery so please be gentle but I cannot seem to get the basic script below to work properly.

The immediate class when loaded is .menuFlyout and when it’s clicked it changes as needed however the second part to change it back does not work. noConflict() doesn’t help.

Thanks in advance for any help.


jQuery(document).ready(function() {
    jQuery('.menuFlyout').click(function(){
        jQuery('.menuFlyout').addClass('closeFlyout');
        jQuery('.menuFlyout').removeClass('menuFlyout');
    });
    jQuery('.closeFlyout').click(function(){
        jQuery('.closeFlyout').addClass('menuFlyout');
        jQuery('.closeFlyout').removeClass('closeFlyout');
    });
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:50:07+00:00Added an answer on June 16, 2026 at 5:50 pm

    Try with this

    jQuery(document).ready(function() {
        jQuery(document).on('click','.menuFlyout', function(){
            jQuery('.menuFlyout').addClass('closeFlyout');
            jQuery('.menuFlyout').removeClass('menuFlyout');
        });
        jQuery(document).on('click','.closeFlyout', function(){
            jQuery('.closeFlyout').addClass('menuFlyout');
            jQuery('.closeFlyout').removeClass('closeFlyout');
        });
    });
    

    The problem with your code is that there is no element with class closeFlyout when you attah the handler. You need to delegate the click handler using on method (see section “Direct and delegated events” for more details ).

    Using event delegation should fix your problem but as a side note here you have 2 improved versions of your code (as sugggested by @wirey and @h0tw1r3)

    jQuery(document).ready(function() {
        jQuery(document).on('click','.menuFlyout', function(){
            jQuery(this).addClass('closeFlyout').removeClass('menuFlyout');
        });
        jQuery(document).on('click','.closeFlyout', function(){
            jQuery(this).addClass('menuFlyout').removeClass('closeFlyout')
        });
    });
    

    or

    jQuery(document).ready(function() {
        jQuery(document).on('click','.menuFlyout, .closeFlyout', function(){
            jQuery(this).toggleClass('closeFlyout');
            jQuery(this).toggleClass('menuFlyout');
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It might be a stupid problem, but I am very new to jQuery. I
Im very new to javascript and jquery so please bear with me. Here's my
i'm very new to jquery, please help me in makeing a for loop or
I am very new to Mootools but have good experience in jQuery. Recently i
Please be gentle, as I'm still new to web programming and -very- new to
I am very new to Jquery so please excuse this noobie question. I am
I'm very new to using jQuery so please excuse me if this question is
I am very new to CSS/Jquery so please forgive the assumed simplicity of this
I am very new to jquery and javascript, hence this query(Please dont mind if
I'm fairly new to asp.net/c# and very new to jQuery so please forgive me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.