Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting an error when using jQuery's click event

Tags:

jquery

there. I'm using jQuery to add a click handler to some buttons I'm using for a calendar, but the context doesn't seem to matter much. I've tried putting anything (or nothing) in the function that's called by the click event.

If I click the button a few (three or four) times in succession, I get an error. It doesn't actually seem to affect the execution of the function itself. It just throws an error, which concerns me, obviously.

The code in question is as follows:

$("#backward").click(function(event){. . .});

And the error I'm getting is:

Error in event handler for 'undefined': INDEX_SIZE_ERR: DOM Exception 1 Error: Index or size was negative, or greater than the allowed value.
at J (chrome-extension://mgijmajocgfcbeboacabfgobmjgjcoja/content_js_min.js:14:142)
at null.<anonymous> (chrome-extension://mgijmajocgfcbeboacabfgobmjgjcoja/content_js_min.js:17:184)
at chrome-extension://mgijmajocgfcbeboacabfgobmjgjcoja/content_js_min.js:1:182
at miscellaneous_bindings:286:9
at chrome.Event.dispatchToListener (event_bindings:379:21)
at chrome.Event.dispatch_ (event_bindings:365:27)
at chrome.Event.dispatch (event_bindings:385:17)
at Object.chromeHidden.Port.dispatchOnMessage (miscellaneous_bindings:253:22) event_bindings:369
chrome.Event.dispatch_ event_bindings:369
chrome.Event.dispatch event_bindings:385
chromeHidden.Port.dispatchOnMessage miscellaneous_bindings:253

Obviously, the problem is with that extension, which is just Google Dictionary.

I'm not sure if the problem is with me or with that, but I'd prefer for my website not to clash with Google Dictionary...

Thanks!

like image 543
River Tam Avatar asked Oct 27 '12 21:10

River Tam


People also ask

Why click is not working?

To turn it on, go to Start > Settings > Devices > Mouse > Related Settings > Additional Mouse Options. The Mouse Properties window will pop up. At the bottom of the Buttons tab, you'll see the ClickLock options. Put a tick in the checkbox to enable it.

How do you trigger an event on click?

The HTMLElement. click() method simulates a mouse click on an element. When click() is used with supported elements (such as an <input> ), it fires the element's click event.

Is jQuery click deprecated?

click() that can be used to attach or trigger event handlers. For a complete list of shorthand methods, see the events category. Deprecated in jQuery 1.8, removed in 1.9: The name "hover" used as a shorthand for the string "mouseenter mouseleave" .

What is the difference between .on click function ()) and .click function?

on() differs from . click() in that it has the ability to create delegated event handlers by passing a selector parameter, whereas . click() does not.


1 Answers

If it's clashing with something else you can always use:

$("#backward").click(function(e){
    e.preventDefault();
    . . .
});
like image 132
Peter Oram Avatar answered Sep 29 '22 12:09

Peter Oram