No onclick for button, div, img with IE 9

html, internet-explorer-9, javascript

Solution

You mentioned that the code works if the user has the developer tools open, which means your problem is most likely that you are using `console.log` statements in your code.

in IE, printing to the console when the developer tools are not open will cause a javascript exception, which would cause your event handlers to stop working.

to get around this problem, wrap all of your console statements with an if statement:

if (console) {
    console.log('foo');
}

Problem

Does anyone know of a workaround for the bug in IE9 where a function in the onclick for these page elements: button, div, img, isn't called? So you click on the element and nothing happens. This came up on a page that I am developing. If I launch the F12 debugger, the problem goes away. But I cannot ask site visitors to click F12 to browse the page! What are the solutions to this? I thought that this might only happen when the element is created dynamically in javascript. But this also happens if the element is defined in the HTML.

Original source

Related problems