Jump to content

jQuery puzzler:


End User

Recommended Posts

On both IE and Firefox, this little bit of code throws the error: "click" is undefined

$('.noclick').live('click', function() {	// prevent passing the click up the event chain	click.stopPropagation();});

I've tried adding "var click;" and "var click=''" directly above the "click.stopPropagation();" line, but then it displays a different error: 'undefined' is null or not an object. Can anyone tell me either what's causing this error message or (hopefully) how to correct it?

Link to comment
Share on other sites

I don't know if the jQuery events are like the Javascript ones, but if it is, you'll have to add an event parameter to the function. For Internet Explorer, use the window.event object.I don't think stopPropagation works in Internet Explorer, but it has the cancelBubble property instead.Try this:

$('.noclick').live('click', function(e) {  // Get the event object, cross-browser  e = e?e:window.event  // Stop event propagation  e.cancelBubble = true;  if(e.stopPropagation) e.stopPropagation();});

Link to comment
Share on other sites

Dang, I'm sad to report that it doesn't work. It doesn't throw an error, but it doesn't stop the event either In IE or Firefox). :)

$('.noclick').live('click', function(e) {  // Get the event object, cross-browser  e = e?e:window.event  // Stop event propagation  e.cancelBubble = true;  if(e.stopPropagation) e.stopPropagation();});

Link to comment
Share on other sites

The docs for jQuery indicate that their event model tries to normalize everything so that you don't need to deal with different browsers. The reference for the event object will list all of the properties and methods you can use.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...