assigning to onmousedown a function that accepts an argument

Discussion in 'Javascript' started by Assaf Lavie, May 6, 2007.

  1. Assaf Lavie

    Assaf Lavie Guest

    I'm creating a HTML element dynamically using javascript and I want to
    assign a handler to its onmousedown.
    var myNewElem;
    ....
    myNewElem = function() { do_somthing(); }

    The handler needs to be able to process the event argument that is
    passed to it. i.e. the actual handler should look like this:
    function mouseDownHandler(e)
    {
    // use e.event_details_etc
    }

    How do I do this?
    myNewElem = function(e) { alert(e); }
    doesn't seem to work. it just says 'e' is undefined.
    Assaf Lavie, May 6, 2007
    #1
    1. Advertising

  2. On May 6, 6:54 am, Assaf Lavie <> wrote:
    > I'm creating a HTML element dynamically using javascript and I want to
    > assign a handler to its onmousedown.
    > var myNewElem;
    > ...
    > myNewElem = function() { do_somthing(); }


    myelem.onmousedown=function(e){doSomething(e||event)}

    function doSomething(e){
    alert(e)
    }

    works in ie,ff,op
    scripts.contact, May 6, 2007
    #2
    1. Advertising

  3. Assaf Lavie

    Assaf Lavie Guest

    On May 6, 4:40 pm, "scripts.contact" <>
    wrote:
    > On May 6, 6:54 am, Assaf Lavie <> wrote:
    >
    > > I'm creating a HTML element dynamically using javascript and I want to
    > > assign a handler to its onmousedown.
    > > var myNewElem;
    > > ...
    > > myNewElem = function() { do_somthing(); }

    >
    > myelem.onmousedown=function(e){doSomething(e||event)}
    >
    > function doSomething(e){
    > alert(e)
    >
    > }
    >
    > works in ie,ff,op


    Tried it and the argument is always undefined (e or event)...
    Assaf Lavie, May 8, 2007
    #3
  4. On May 8, 2:50 am, Assaf Lavie <> wrote:
    > > > I'm creating a HTML element dynamically using javascript and I want to
    > > > assign a handler to its onmousedown.

    ....
    > Tried it and the argument is always undefined (e or event)...


    Try:


    [element].onmousedown=x

    function x(e){
    alert((e||event).clientX)
    }
    scripts.contact, May 8, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kyzer
    Replies:
    2
    Views:
    763
    Duane Hebert
    May 6, 2005
  2. Reckoner
    Replies:
    11
    Views:
    698
    Steven D'Aprano
    Jan 19, 2009
  3. AikidoGuy
    Replies:
    11
    Views:
    558
    Seebs
    Nov 21, 2011
  4. Tom Agnew
    Replies:
    3
    Views:
    99
    Ara.T.Howard
    Oct 31, 2005
  5. weston
    Replies:
    1
    Views:
    248
    Richard Cornford
    Sep 22, 2006
Loading...

Share This Page