assigning to onmousedown a function that accepts an argument

A

Assaf Lavie

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.
 
S

scripts.contact

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
 
A

Assaf Lavie

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)...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top