Jquery click registers in FIrefox, not in IE
what might be a reason for a simple click to reg开发者_开发问答ister in firefox and not in IE?
Edit: I should get points just for figuring out problem with such a bad question.
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;
});
});
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");
});
精彩评论