I want to pass parameters to function trigerred by click, where first parameter is event object and second is for example some string. I've got something like that:
HTML Code:
function load() {
var modal = document.getElementById('modal');
modal.addEventListener('click', function () {placeDiv(event, 'orange')} )
}
function placeDiv(e, color) {
alert(e.button+' '+color); //test
}
It works fine in IE and Opera but in FF nothing happens. Can anyone solve this problem? Thanks in advance
modal.addEventListener('click', function (event) {placeDiv(event, 'orange');} );
That should work, but I prefer to explicitly write it as something like:
Code:
modal.addEventListener('click', function (e) {e = e || window.event; placeDiv(e, 'orange');} );
I'm a fan of semi-colons too as you can see!
In fact, as far as I know you don't need to pass window.event as a parameter at all in IE, but you absolutely do in Firefox, they only have the W3C model.
Last edited by Declan1991; 05-07-2012 at 03:13 PM.
Great wit and madness are near allied, and fine a line their bounds divide.
Bookmarks