Jquery click event assignment not working in Firefox
I am assigning a click event to a group of anchors by class name and it works in all browsers except Firefox, here is the JS:
var click_addthis = function(e, href) {
if (!e) {
var e = window.event;
}
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
window.open(href, "Share It", null);
return false;
}
$(document).ready(function() {
$(".addthis_button_facebook").click(function() { click_addthis(event, this.href) });
$(".addthis_button_twitter").click(function() { click_addthis(event, this.href) });
});
Am I missing something? Thanks to
+2
a source to share
1 answer
The problem area for Firefox is the section:
$(document).ready(function() {
$(".addthis_button_facebook").click(function() { click_addthis(event, this.href) });
$(".addthis_button_twitter").click(function() { click_addthis(event, this.href) });
});
You need to pass the event from the handler to be consistent, e.g .:
$(document).ready(function() {
$(".addthis_button_facebook").click(function(e) { click_addthis(e, this.href) });
$(".addthis_button_twitter").click(function(e) { click_addthis(e, this.href) });
});
You can also shorten it to this, since you are using the same function ( return false
also stops propagation):
$(document).ready(function() {
$(".addthis_button_facebook, .addthis_button_twitter").click(function() {
window.open(this.href, "Share It", null);
return false;
});
});
+6
a source to share