jQuery click event behaves differently with live function in Firefox

Using the event click with live function leads to strange behavior when using Firefox*. With live in Firefox, click is triggered when right-clicking also! The same does not happen in Internet Explorer 7 neither in Google Chrome.

Example:

  • Without live, go to demo and try right clicking the paragraphs. A dialog menu should appear.
  • With live, go to demo and try right clicking "Click me!". Now both dialog menu and "Another paragraph" appear.

*tested with firefox 3.5.3

-------------Problems Reply------------

As far as I know, that is a known issue (bug?). You can easily work around it by testing which button was clicked as follows:

$('a.foo').live("click", function(e) {
if (e.button == 0) { // 0 = left, 1 = middle, 2 = right
//left button was clicked
} else {
//other button was clicked (do nothing?)
//return false or e.preventDefault()
}
});

you might prefer using a switch depending on your specific requirements, but generally you would probably just want to do nothing (or or simply return) if any button other than the left button is clicked, as above:

$('a.foo').live("click", function(e) {
switch(e.button) {
case 0 : alert('Left button was clicked');break;
default: return false;
}
});

I think it's a known "bug", you could potentially query the event object after attaching the click handler ( which gets attached to the document ) and see if its a right click, otherwise manually attach the click handler after you manipulate the DOM.

After looking it up, e.button is the property you want to query:

.live('click', function(e){

if ( e.button == 2 ) return false; // exit if right clicking

// normal action

});

See my answer here: if you don't mind changing the jQuery source a bit, adding a single line in the liveHandler() works around the problem entirely.

Category:jquery Views:1 Time:2009-09-27

Related post

  • jQuery Click event on asp:button 2009-04-04

    I have a server side button as <asp:Button ID="btnSummary" runat="server" OnClick="btnSummary_Click" Text="Next" /> I want to attach the jQuery Click event using its ID and NOT using the alternative class attribute way. I tried to attach the cl

  • JS/Jquery: Click Event After AddClass 2011-02-22

    Say I want to change a container's class when the image it contains is loaded, probably something like this: $('.image').load(function(){ $(this).parents('.image-wrapper').removeClass('image-wrapper').addClass('image-wrapper-new'); }); …And then add

  • How to pass parameter dynamically to JQuery click event from HTML elements? 2011-04-12

    First of all, I have to mention that I am a newbie in the JavaScript and JQuery world. I am not sure if I put down an appropriate title for my question but I'll try my best to explain my problem. Scenario: I have a list of items whose names are being

  • How can I execute jQuery click() event before a JSF or action is performed? 2011-04-28

    Trying to bind click confirmation with jQuery (to clean code in JSF page) I understand that onclick inline function (oamSubmitForm();) written by MyFaces is executed before jQuery click() event. Is possible to do jQuery click before instead? jQuery("

  • Why some time jquery click event fails? 2011-05-11

    My page is divided into two parts vertically.Left part is like a menu section. Clicking on any menu brings the proper data related to that menu in the right part of the page. I am doing it using ajax call and the only div on the right part get refres

  • jQuery: Click event detected many times 2011-07-04

    I have a problem with jQuery click event handling. Here's my code: $j("#btn_renommer_groupe").click(function(){ document.forms['creation_edition_groupe'].reset(); $j("#img_saisie_nom_groupe").hide(); $j("input[name=creation_groupe]").css("background-

  • Jquery click event inside each loop not working in IE 2011-07-25

    I've inherited this bit of code and I'm trying to get it working. It's generating a select menu that's being used to filter a page of products. Originally, it was generating a UL (options were LIs), but it's now being converted to a select list. The

  • How to process a JSON object from $.getJSON with a jQuery Click event? 2011-09-17

    I am not sure whether this is a silly question... I am trying to sort a JSON array using jQuery click event. The following is a simplified html code which I thought should work: <SCRIPT type='text/javascript'> function results(json) { // displa

  • mixing my jQuery click events with existing object's onclick attribute 2011-09-21

    I'm using jQuery but dealing with markup produced from JSF pages. A lot of the elements have onclick attributes provided by the JSF code (which isn't my realm). Example: <div onclick="[jsf js to submit form and go to next page]">submit</div

  • jquery click event handler for items within a div 2011-09-30

    How do you add a jquery click event handler for a bunch of links within a div? For example: <div class="test"> <a href="test1.html">link 1</a> <a href="test2.html">link 2</a> <a href="test3.html">link 3</a>

  • How can I retrieve the child position of a list item during a jQuery click event? 2011-10-18

    How can I retrieve the child position of a list item during a jQuery click event? ul li li li $('li').click(//pass index of li into function) --------------Solutions------------- If all you want to do is find out which li was clicked in the alert: $(

  • Can jquery click event simular mousewheel up and down? 2011-10-24

    Can jquery click event simulate mousewheel up and down? I tried to reach some function link: click up arrow, simulate mousewheel up. click down arrow, simulate mousewheel down. <a id="up">up</a> <a id="down">down</a> $('#up').

  • How do I apply a jquery Click event to dynamic list elements? 2011-11-01

    My current setup loads a dynamic list at which point I create a click event via jquery like so: $('#listReports li').click(function () { var selected = $(this).text(); alert("List Item: " + selected); }); I have code that lets a user save a report wh

  • jQuery click event when an element is inside another element 2011-11-07

    I have a problem with the jQuery click event when an element is inside another element. The code I am using is similar to the following: <div class="a" id="a"> <a class="b" id="b"></a> </div> $(".a,.b").click(function() { var

  • How to add a some condition in jquery click event? 2011-11-07

    I have a many elements with "click" events. How to add a some condition in jquery click event for all buttons ? Override standart click event ? for example: if ( my_condition ) { return click(); } else { return false; } --------------Solutions-------

  • jquery click event for checking one main checkbox and disable all other 2011-12-02

    i m trying to make a function in jquery to disable a group of checkboxes on click one main checkbox function is function DisableCheckboxes(id) { if($(this).is(':checked')) { $("input[name="+id+"]").each(function(){ $(this).attr({ 'checked':false, 'di

  • jQuery click event has a 4-5 seconds lag before firing in IE7 / 8 2011-12-22

    A jQuery click event has a 4-5 seconds lag before firing in IE7 & IE8. Is it just due to IE JS engine? Site in question: http://www.shirtlisted.com/made-to-measure/ (click on a fabric to fire event) here is the code snippet: $('.fabric-item').del

  • Why is my PostBack occurring before my jQuery click event? 2012-01-25

    I'm fairly new to jQuery, but I have some links on my page which should toggle sections of the form visible when clicked, or if javascript is disabled it does a full postback to toggle those sections It works fine in my test environment, with the Pos

  • jquery click event bubbling 2012-03-09

    I'm having an issue that seems to be related to event bubbling. When the user clicks on a list item I store the innerHTML of that element to a variable and replace the list item content with a textbox having the value of the new variable. This works

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.167 (s). 11 q(s)