Is it OK to use <div> to change text and images?

O

OM

I've found out that I can use <div id = "variable"><div> to change text and
pictures on mouseovers.

All I have to do is change "variable" to be the HTML text I want.

I can even change the text to have images.

Is this method recommended?

Should I be doing it another way?

Any help would be appreciated.

THANKS.


OM

(Before anyone complains... sorry about the amount of messages posted.)
: )
 
L

Lasse Reichstein Nielsen

OM said:
I've found out that I can use <div id = "variable"><div> to change text and
pictures on mouseovers.

All I have to do is change "variable" to be the HTML text I want.

I am not sure what you mean. Do you just write
variable = "html code"
or do you write
variable.innerHTML = "html code"
?

The latter works in some browsers, but not all.
I can even change the text to have images.

Is this method recommended?

No. If you need to refer to the div with id="variable", it is not
recommended to just write "variable" or "document.variable". Some
browsers make that work, others don't, and noone say that they
should.

The recommended method is:
document.getElementById("variable")

To change the contents of the div, you can assign to the innerHTML
property. It is not standard, but is widely available.
Should I be doing it another way?

I prefer the W3C DOM methods to build content. To add an image to the
div, I would write

var myImg = document.createElement("img");
img.src = "PicA.png";
document.getElementById("variable").appendChild(img);

It is longer than using innerHTML, though.

/L
 

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
474,091
Messages
2,570,604
Members
47,223
Latest member
smithjens316

Latest Threads

Top