firefox error on page refreshing

K

kantix

Hi,

I have problem in my script. My function takes images and puts
colored border on them depending on if they are selected or mouse is
on them. But on FF when I load page and move my mouse over those
pictures (at the same time) I get an error:
document.getElementById(this.id) has no properties. Here I put a piece
of my code where error happens. (If you need more - tell me).

newtd.onmouseover = function() {
if (document.getElementById(this.id).className=='onclick') {
document.getElementById(this.id).className='onclick'
}
else if (document.getElementById(this.id).className=='offtd') {
document.getElementById(this.id).className='ontd'
}
}

I add those pictures and all table dynamically using appendChild().

Looks like there is no errors on IE and Opera.

Maybe someone know why is this happening and how to aviod it? :)

Thanks!
 
H

Henry

I have problem in my script. My function takes images and puts
colored border on them depending on if they are selected or mouse
is on them. But on FF when I load page and move my mouse over those
pictures (at the same time) I get an error:
document.getElementById(this.id) has no properties. Here I put a
piece of my code where error happens. (If you need more - tell me).

newtd.onmouseover = function() {
if (document.getElementById(this.id).className=='onclick') {
<snip> ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^

Crazy logic. When you use getElementById with a value you get (if it
exists, or exists at the time) a reference to an element with the ID
attribute that was used as an argument. If you use - this.id - as the
argument you are reading the - id - property of an object, that will
be an Element if the code is in an intrinsic event handler, and if it
is an element its - id - property will be the equivalent of the
element's ID attribute.

That is, you are reading the id off an element and then using that to
get a reference to the element that has the id; the element you
started with. Replace all occurrences of:-

document.getElementById(this.id)

- with:-

this

- and you will save your code from going through a number of
operations that are pointless.
 
K

kantix

On Aug 10, 1:58 pm, (e-mail address removed) wrote:> I have problem in my script. My function takes images and puts


<snip> ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^

Crazy logic. When you use getElementById with a value you get (if it
exists, or exists at the time) a reference to an element with the ID
attribute that was used as an argument. If you use - this.id - as the
argument you are reading the - id - property of an object, that will
be an Element if the code is in an intrinsic event handler, and if it
is an element its - id - property will be the equivalent of the
element's ID attribute.

That is, you are reading the id off an element and then using that to
get a reference to the element that has the id; the element you
started with. Replace all occurrences of:-

document.getElementById(this.id)

- with:-

this

- and you will save your code from going through a number of
operations that are pointless.

Thanks, it helped :)
 

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

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,278
Latest member
BuzzDefenderpro

Latest Threads

Top