Javascript Div Issues.
November 13, 2006 4:05 PM
Subscribe
Javascript neophyte: How do I swap out the contents of one div with another? But there is a monkey-wrench in the whole thing: the new div
So, this is the situation:
I want to present a picture, which a user can click. When a user clicks that image, the image disappears, and javascript loads up a chunk of html/javascript, in the spot where the image was, that does some fairly fancy javascripty stuff itself, like phpadsnew adlogic, and stuff like that.
The problem I'm having is this: I can get this to work with fairly simple html, using innerHTML, but I run into problems when the html contains javascript, and script tags.
This is the code I'm trying to use:
<div id="DivExample">
<img ="http://ourobouros.net/thingy.gif"
onclick="document.getElementById('DivExample').innerHTML='Hi!<br> this is a test<br><a href=http://google.com>google</a>'">
</div>
And this is the sort of javascript that i'd like to have run when the new html loads in the div:
<SCRIPT SRC="http://example.com/random.js" LANGUAGE="JavaScript"></SCRIPT>
I've thought of a couple of possible solutions: iframes, calling another page, with the correct html and javascript, altering the html/javascript with html entities so that javascript doesn't choke on some character somewhere.
I'm pretty much a complete noob, but fairly conversant with php. Any help would be greatly appreciated.
posted by Freen to computers & internet (12 comments total)
posted by jlub at 4:35 PM on November 13, 2006