I would like to know how I can pass an argument to someFunction when it is the result of my onlick event so I can also use someFunction() without having to clone it (and change its name slightly) just so it can receive an argument.
I hope my problem is clear so I can get an answer…
You can let your function decide if it is being passed a string.
function someFunction(){
if(typeof arguments[0]=='string'){
// use the argument as a string
}
else{
// use argument[0](as an event or a 'this' element)
}
// more code
}
or
function someFunction(hoo){
if(typeof hoo=='string')hoo=document.getElementById(hoo);
else hoo= hoo? hoo.target : window.event && event.srcElement;
// more code using element hoo
}
function someFunction(){
if(typeof arguments[0]=='string'){
// use the argument as a string
}
else{
// use argument[0](as an event or a 'this' element)
}
// more code
}