PDA

View Full Version : Changing things with div


Thamior
05-26-2004, 07:44 PM
i asked awhile ago and got a function for displaying text however I wish to know the various elements so I can use to it to change things like images or background colors, or anything like that.

<script type="text/javascript">
function describe(text) {
if (document.getElementById) {
document.getElementById('one').innerHTML = text; }
else {
document.all.one.innerHTML = text;
}
}
</script>

agent002
05-27-2004, 06:35 AM
.innerHTML works on any tag that has a corresponding closing tag, e.g. <body> (as it also has </body>). It changes the content between the opening and closing tags, so if you have
<span></span>
and change the .innerHTML to "Hello", you get
<span>Hello</span>
It doesn't work on tags without closing tags, however, such as <input>, becase there's no logical place to insert the data in.

There's also a property called .outerHTML which also includes the opening and closing tags; if you have
<span></span>
again and change the .outerHTML to "Hello", you get
Hello

Thamior
05-27-2004, 10:17 AM
so if i have an image between div tags and then use innerhtml to replace it the image should change?

agent002
05-27-2004, 10:44 AM
Yup. But if you're simply going to change the image source... it is probably easier to change whatEverImageObject.src.

Thamior
05-29-2004, 01:38 AM
yea I just got a javascript book, i have read it before but i'm still bad at javascript. its wierd I know C++.

when doing that it doesnt work heres the code:

function whenload()
{
document.image[0].src="yellow.jpg";
document.image[1].src="red.jpg"
}
function swapimg()
{
document.image[2].src = document.image[0].src;
document.swap.src = document.image[1].src;
document.image[1].src = document.image[2].src;
}
function normal()
{
document.image[2].src = document.swap.src;
document.swap.src = document.image[1].src;
document.image[1].src = document.image[2].src;
}

agent002
05-29-2004, 04:04 AM
I believe it should be document.images[0].src :)