Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Adding Events to newly created controls question...

Reply
Thread Tools

Adding Events to newly created controls question...

 
 
xxbmichae1@supergambler.com
Guest
Posts: n/a
 
      11-06-2005
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

 
Reply With Quote
 
 
 
 
Mick White
Guest
Posts: n/a
 
      11-06-2005
wrote:

> 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
 
Reply With Quote
 
 
 
 
xxbmichae1@supergambler.com
Guest
Posts: n/a
 
      11-06-2005
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!

 
Reply With Quote
 
Mick White
Guest
Posts: n/a
 
      11-06-2005
Mick White wrote:

>>

> 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
 
Reply With Quote
 
Mick White
Guest
Posts: n/a
 
      11-06-2005
wrote:

> 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!
>

http://www.mozilla.org/docs/dom/domref/dom_shortIX.html

Mick
 
Reply With Quote
 
Mick White
Guest
Posts: n/a
 
      11-06-2005
Mick White wrote:

> Mick White wrote:
>
>>>

>> 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';}
>

Caveat: The image needs to be appended to its parent before you may
reference the parentNode.
Mick
 
Reply With Quote
 
xxbmichae1@supergambler.com
Guest
Posts: n/a
 
      11-08-2005
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

 
Reply With Quote
 
web.dev
Guest
Posts: n/a
 
      11-08-2005

wrote:
> 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";

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


 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      11-08-2005
wrote:

> 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/>
 
Reply With Quote
 
xxbmichae1@supergambler.com
Guest
Posts: n/a
 
      11-08-2005
thanks!

 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamically adding controls with events (but events are not firing) SevDer ASP .Net 2 11-13-2007 06:33 AM
Linking events from controls, when the controls have been created =?Utf-8?B?cml2YWxAbmV3c2dyb3Vwcy5ub3NwYW0=?= ASP .Net 3 07-16-2007 04:02 PM
Importing a list of existing addresses into a newly created "List" Dan Firefox 2 05-10-2005 07:50 PM
Adding events to dynamically created controls JezB ASP .Net 2 06-18-2004 02:54 PM
Newly Created Image Not Always Found by Following Code Earl Teigrob ASP .Net 0 08-05-2003 03:39 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57