Laser Lips escribió:
Is it possible to do the following?
object = document.getelementById('something');
object.onmouseover='alert("hi");';
[...]
I know that object.onmouseover=function(){alert("hi");} is OK but I
want to do it the first way. Can it be done?
Do you need to execute code from a string or is it just an aesthetics
question?
In the latter case, this is not HTML; you don't need to pack all your
code in one line. So (in my humble opinion) this looks just fine:
object.onmouseover = function(){
alert("hi");
};
You can also assign a named function:
function sayHi(){
alert("hi");
}
object.onmouseover = sayHi;
In the former case you'd have to do this:
object.onmouseover = function(){
eval('alert("hi");');
};
Not a good idea unless there's powerful reason.
--
--
http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:
http://bits.demogracia.com
-- Mi web de humor al baño María:
http://www.demogracia.com
--