Adding Events to newly created controls question...

X

xxbmichae1

I'm having a hard time getting this code to work...the onMouseOver and
onMouseOut events don't seem to be firing in IE or Mozilla.....thanks
in advance for any assistance...

var imgf = document.createElement("img");
imgf.src = "../files/img.gif";
imgf.style.cursor = "pointer";
imgf.style.border = "1px solid blue";
imgf.title = "Date selector";

// below is not working at all......

imgf.onMouseOver = "this.style.background='blue';";
imgf.onMouseOver = "this.style.background='';";


Thanks again!

Michael
 
M

Mick White

I'm having a hard time getting this code to work...the onMouseOver and
onMouseOut events don't seem to be firing in IE or Mozilla.....thanks
in advance for any assistance...

var imgf = document.createElement("img");
imgf.src = "../files/img.gif";
imgf.style.cursor = "pointer";
imgf.style.border = "1px solid blue";
imgf.title = "Date selector";

// below is not working at all......

imgf.onMouseOver = "this.style.background='blue';";
imgf.onMouseOver = "this.style.background='';";
imgf.onmouseover = function(){this.style.backgroundColor='blue';}

Mick
 
X

xxbmichae1

Thanks you very much.....looked all over the place for this....is there
a good DOM reference book you know of?? or where info like this is
located?

Thanks again!
 
M

Mick White

Mick said:
imgf.onmouseover = function(){this.style.backgroundColor='blue';}


Oops, makes no sense to assign a background colour to an image

imgf.onmouseover = function(){this.parentNode.style.backgroundColor='blue';}

Mick
 
M

Mick White

Mick said:
Oops, makes no sense to assign a background colour to an image

imgf.onmouseover =
function(){this.parentNode.style.backgroundColor='blue';}
Caveat: The image needs to be appended to its parent before you may
reference the parentNode.
Mick
 
X

xxbmichae1

Thanks Mick.....you seem very knowledgable on these things, mind if I
ask you another question.....

I'm trying to set the class of a newly created object

I've tried the following two statements...

imgf.class = "classname";
imgf.style.class = "classname";

This doesn't seem to work, it causes a JavaScript error message......do
you know the correct syntax?

Thanks

Michael
 
W

web.dev

Thanks Mick.....you seem very knowledgable on these things, mind if I
ask you another question.....

I'm trying to set the class of a newly created object

I've tried the following two statements...

imgf.class = "classname";
imgf.style.class = "classname";

Correct syntax is as follows:

imgf.className = "classname";
 
T

Thomas 'PointedEars' Lahn

I'm trying to set the class of a newly created object

I've tried the following two statements...

imgf.class = "classname";
imgf.style.class = "classname";

This doesn't seem to work, it causes a JavaScript error message......

"a JavaScript error message" is as bad an error description as any.
do you know the correct syntax?

<FAQENTRY>

Since `class' is a reserved word in several interfacing languages,
including JS/ECMAScript, it cannot be used for identifiers which is
why the DOM Level 2 HTML ECMAScript binding specifies the `class'
attribute of HTML elements to be accessible through the implemented
`className' attribute of HTMLElement objects.

imgf.className = "classname";

See <http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-213157251>.

</FAQENTRY>

BTW, that is a FAQ here; not covered by the FAQ list[1] yet, however it can
be searched through (Google Groups) archives which is the first thing one
should do before posting.

<http://jibbering.com/faq/#FAQ2_11>


PointedEars
___________
[1] <http://jibbering.com/faq/>
 
X

xxbmichae1

Thanks Thomas, I tried searching first and came up with nothing
useful....I'll search the link you provided first next time.
 

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,770
Messages
2,569,586
Members
45,097
Latest member
RayE496148

Latest Threads

Top