By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,340 Members | 1,625 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,340 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.)
: )
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"OM" <OM@yahoo.com> writes:
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(im g);

It is longer than using innerHTML, though.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.