|
Today I’m going to show you how to make a <div> = the contents of a javascript variable. It’s actually very simple to do!
First lets start with the <div>
<div id=”thediv”></div>
Now lets do the javascript. Areas you will need to change are in bold.
<script type=”text/javascript”>
var thevar = “This is a test“;
document.getElementById(’thediv‘).innerHTML = thevar;
</script>
var thevar = “This is a test“;
document.getElementById(’thediv‘).innerHTML = thevar;
</script>
That will make the div contents, “thediv” equal to the variable of “thevar”.
But what if we want to make the div equal another div? Easy! Just turn it around…
<script type=”text/javascript”>
var thevar = “This is a test”;
document.getElementById(’thediv‘).innerHTML = document.getElementById(’OTHERDIV‘).innerHTML;
</script>
var thevar = “This is a test”;
document.getElementById(’thediv‘).innerHTML = document.getElementById(’OTHERDIV‘).innerHTML;
</script>
|



Thank you very much. Exactly what I was looking for.