473,395 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Adding Events to newly created controls question...

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

Nov 6 '05 #1
10 1152
xx********@supergambler.com 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
Nov 6 '05 #2
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!

Nov 6 '05 #3
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
Nov 6 '05 #4
xx********@supergambler.com 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
Nov 6 '05 #5
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
Nov 6 '05 #6
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

Nov 8 '05 #7

xx********@supergambler.com 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


Nov 8 '05 #8
xx********@supergambler.com 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/>
Nov 8 '05 #9
thanks!

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

Nov 8 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Amir Hardon | last post by:
I'm new to DOM and can't figure out this thing: I'm trying to add a row to a table with a form field in one of it's cells, but if I'm appending the field to a form it gets out of the table. Can...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
2
by: JezB | last post by:
I'm adding WebControl objects to a Page dynamically on Page_Load, but I'm having trouble attaching events to these. For example, adding an image button :- ImageButton nb = new ImageButton();...
0
by: Steve Moreno | last post by:
Hi all, I've got a web form that I've written code to create an array of DropDownList controls on the page depending on how many records are pulled back. The code to create the controls is...
5
by: Steve Moreno | last post by:
Hi all, I've got a web form that I've written code to create an array of DropDownList controls on the page depending on how many records are pulled back. The code to create the controls is...
9
by: Neo Geshel | last post by:
I have strip-mined, strip-searched, and completely exhausted the Internet (up to the 30th page on Google, with 100 results per page!!), all without finding an answer to my question AS TO WHY IT...
2
by: Oleg Ogurok | last post by:
Hi all, Does anyone have example of adding controls on the client side (DHTML) and then persisting them as ASP.NET server controls on the server side? For example, a page has an <input>...
6
by: Totto | last post by:
Hi, Anyone know the best solution to dynamically add buttons to a asp 2.0 page using data from Sql server? Are there any contols suitable for this or is it best to iterate the dataset and...
5
by: Amoril | last post by:
I've read quite a few different message on various boards and for some reason I'm still having trouble wrapping my head around this viewstate maintenance and trying to get these dynamically created...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.