HighDots Forums  

object.onmouseover

Javascript JavaScript language (comp.lang.javascript)


Discuss object.onmouseover in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Laser Lips
 
Posts: n/a

Default object.onmouseover - 05-21-2008 , 09:58 AM






HI All,

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?

Graham

Reply With Quote
  #2  
Old   
Martin Honnen
 
Posts: n/a

Default Re: object.onmouseover - 05-21-2008 , 10:01 AM






Laser Lips wrote:

Quote:
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?
Assigning a function makes sense, assigning a string as you do does not
make sense. So it can be done but is not in any way useful. If you have
a string then you need to create a function from it:
object.onmouseover = new Function('alert("hi");');


--

Martin Honnen
http://JavaScript.FAQTs.com/


Reply With Quote
  #3  
Old   
Laser Lips
 
Posts: n/a

Default Re: object.onmouseover - 05-21-2008 , 10:10 AM



Thats just what I needed thanks. :0)
Graham

Reply With Quote
  #4  
Old   
Álvaro G. Vicario
 
Posts: n/a

Default Re: object.onmouseover - 05-21-2008 , 10:30 AM



Laser Lips escribió:
Quote:
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
--


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.