Setting <DIV> Background with JS

M

MC

Hi,

I am trying to set the background color of a div using js.

The error I get in IE is document.myform.mydiv.style is null or not an
object.

Ideas?

Thanks,
MC
 
J

Joost Diepenmaat

MC said:
Hi,

I am trying to set the background color of a div using js.

The error I get in IE is document.myform.mydiv.style is null or not an
object.

Ideas?

document.getElementById('mydiv').style.backgroundColor = 'red';
 
M

MC

Joost,

Getting by ID instead of direct element reference did get the object, but
did not change the background.

Thanks,
MC
 
J

Joost Diepenmaat

MC said:
Joost,

Getting by ID instead of direct element reference did get the object, but
did not change the background.

So what happens if you set the style's background color in the HTML directly?
 
M

morbidKK

Hi,

I am trying to set the background color of a div using js.

The error I get in IE is document.myform.mydiv.style is null or not an
object.

Ideas?

Thanks,
MC

Try using runtimeStyle /currentStyle..that should work..but this wont
work in any other browser
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,824
Members
47,369
Latest member
FTMZ

Latest Threads

Top