Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing insertAdjacentHTML() ?

Status
Not open for further replies.

kosmokramer

Programmer
Sep 8, 2002
73
US
Hey. I am making a rollover for one of my webpages which will take as arguments the image name, the width to make the image, and a description. When the link is rolled over, it will display in one cell of a table the picture and below it in another cell, the description.

Code:
function changeImage(theImage,newWidth,description)
{
    theImageObject = document.all('imagePlaceHolder');
	theImageObject.src=theImage;
	theImageObject.width=newWidth;
	descriptionHolder = document.all('theDescription');
	descriptionHolder.insertAdjacentHTML('BeforeEnd', description);
}

The problem is that the text is not replaced by the new text, it is simply appended on the end of the first text. Also, and this is a minor problem, but since insertAdjacentHTML() is an IE only function, how do I make it compatable with Netscape?
 
Well, since document.all is IE only as well, perhaps try rewriting it like so:
Code:
function changeImage(theImage,newWidth,description)
{
    theImageObject = document.getElementById('imagePlaceHolder');
    theImageObject.src=theImage;
    theImageObject.width=newWidth;
    descriptionHolder = document.getElementById('theDescription');
    descriptionHolder.innerText = description;
}
 
...uuh one more problem. I am passing the description as a string and it is printing out exactly what I put in...in other words if I put in: Go to<a href='someSite.html'> this site </a> it will print out Go to<a href='someSite.html'> this site </a> instead of Go to this site (with this site being underlined). I figure I will have to parse the string or something, but even when I isolate the html tag, I am not sure how to tell it that the text is not a string to just be printed out, but rather a hyperlink
 
[tt]descriptionHolder.innerText = description;[/tt]
[tt]descriptionHolder.innerHTML = description;[/tt]

Should do the trick for you... no string parsing needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top