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

  • Home
  • SEARCH
  • 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 1036301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:40:53+00:00 2026-05-16T14:40:53+00:00

jQuery(a).not(div#mnuMain a).live(click, function(event){ event.preventDefault(); alert(yes I got u); }); How to make it work?

  • 0
jQuery("a").not("div#mnuMain a").live("click", function(event){
                event.preventDefault();
                alert("yes I got u");                 
        });

How to make it work?

  • 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-05-16T14:40:54+00:00Added an answer on May 16, 2026 at 2:40 pm

    Try putting it all in the main selector:

    Example: http://jsfiddle.net/8Tkex/

    jQuery("a:not(div#mnuMain a)").live("click", function(event){
                event.preventDefault();
                alert("yes I got u");                 
        });
    

    EDIT:

    The reason using .not() didn’t work is that when you use jQuery’s live() method, you’re not actually placing the click handler on the element. Instead you’re placing it at the root of the document.

    This works because all click (and other) events on the page “bubble up” from the element that actually received the event, all the way up to the root, thus firing the handler that you placed at the root using .live().

    Because this occurs for every click on the page, jQuery needs to know which item received the click so it can determine which (if any) handler to fire. It does this using the selector you used when you called .live().

    So if you did:

    jQuery("a").live("click", func...
    

    …jQuery compares the "a" selector to every click event that is received.

    So when you do:

    jQuery("a:not(div#mnuMain a)").live("click", func...
    

    …then jQuery uses "a:not(div#mnuMain a)" for the comparison.

    But if you do

    jQuery("a").not("div#mnuMain a").live("click", func...
    

    …the selector ends up looking like "a.not(div#mnuMain a)", which wouldn’t match anything, since there’s no .not class on the <a> element.

    I think some methods may work with live(), but .not() isn’t one of them.

    If you’re ever curious about what the selector looks like for your jQuery object, save your object to a variable, log it to the console and look inside. You’ll see the selector property that jQuery uses.

    var $elem = jQuery("a").not("div#mnuMain a");
    
    console.log( $elem );
    

    …should output to the console something like:

    Object
         context: HTMLDocument
         length: 0
         prevObject: Object
         selector: "a.not(div#mnuMain a)"  // The selector that jQuery stored
         __proto__: Object
    

    This is the output I get from Safari’s console.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<div id=main> hello world <div id=second-div> bye </div> </div> jQuery('#main:not(second-div)').click(function() { alert('works!'); }); I
jQuery('div').not(#supcont).bind('click', function() { jQuery(#supcont).slideUp(slow); }); On: jQuery(#supcont).click(); Acts like #supcont is not exluded. Why?
Changes I make to the classes of a div using jQuery's .removeClass() do not
Jquery did not carry out!!!I don't know why $(.other-edithion).click(function(){ var city = $(this).closest('#city'); if
Any ideas why this jquery is not working? $(div.aboutText p a).each( function() { $(this).replace('
I am getting error jquery is not defined.. please help me.. jQuery(function(){ jQuery('#submitid').click(function(){ if(jQuery('input[id=EnrollmentServiceAddress1]').val()
Popups in jQuery Mobile not working as intended, please advice. The popup DIV is
I have a problem with jQuery, I want to change a DIV (not the
jQuery 1.4: $('#menu li:last:not(.ignore)').addClass('last'); HTML: <div id=menu> <ul> <li>item 1</li> <li>item 2</li> <li class=ignore>item3</li>
How to get width of div using jquery $(#window).width(); is not working <div id=widnow></div>

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.