views:

233

answers:

2

what might be a reason for a simple click to register in firefox and not in IE?

Edit: I should get points just for figuring out problem with such a bad question.

+2  A: 

Note that "click" events don't bubble in IE. If you do something like put a button inside an anchor tag, the button click will not propagate out to the anchor.

I've worked around that with something like this:

$('a').find(':button').each(function() {
  var $button = $(this);
  $button.click(function(ev) {
    $button.closest('a').each(function() {
      this.click(); // not $(this)
    });
    return !!ev.stopPropagation() && false;
  });
});
Pointy
not the actual reason, but it helped me to think and figure out problem.
zsharp
You gave so little info, how could anyone figure out what was the problem? I don't know any mind reading programmers.
LiraNuna
but i solved it thanks to my question.
zsharp
+1 for having magic abilities!
Felix Kling
+2  A: 

There are various ways to click, working in both Firefox and IE. You could use the click method:

$("a:first").click();

Which triggers the click event. Or you could patch it through the trigger method:

$("a:first").trigger("click");

Which does the same thing. These two examples cover the invoking of a click, but not the intercepting. Your question isn't clear about which item you're interested in. Intercepting clicks are similar to the first method:

$("a:first").click(function(e){
  e.preventDefault();
  alert("You've clicked the first link.");
});

This only works for links which are present on the page when jQuery is loaded. If you are loading in dynamic links in the future, you'll have to use the live method:

$("a").live("click", function(e){
  e.preventDefault();
  alert("You've clicked a link");
});
Jonathan Sampson