Results 1 to 3 of 3

Thread: Passing parameters with event object

Hybrid View

  1. #1
    Join Date
    Nov 2011

    Passing parameters with event object

    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

  2. #2
    Join Date
    Aug 2007
    modal.addEventListener('click', function (event) {placeDiv(event, 'orange');} );
    That should work, but I prefer to explicitly write it as something like:
    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 04:13 PM.

  3. #3
    Join Date
    Nov 2011

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center