jQuery Click binding does not fire in IE8
10,882
Solution 1
Have you tried using .on()
?
.on()
will create an event handler for all current and future elements that match your selector. In the statement below the click
event will be handled for all elements with a class of button-next
regardless of when they are added to the DOM.
$(document).on('click', '.button-next', function(e)
{
//do something
});
Solution 2
Try something like this
$(document).on('click', '.button-next', function() {
// code here
});
Author by
contactmatt
Updated on June 14, 2022Comments
-
contactmatt almost 2 years
The jQuery click binding is never fired in IE8 (works in IE9, Chrome, etc.) How can I get the click event to fire in IE8, and why is it not currently?
Note: I've tried changing the href to '#', but that is not working either.
$('<a/>', { id: 'anchor-id', href: 'javascript:void(0);', 'class': 'button-next', html: 'HTML' }).click(function() { alert('clicked'); }).appendTo($('#append'));
version: 1.7.2
-
goodeye almost 9 years+1 for
on
to bind it. I used$('.some-element-class')
instead of$(document)
to get "closer" to the element, instead of searching the whole dom. Still had to be sure to choose an element that IE8 knew was there.