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;

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;

One Response to “how to make div = javascript variable”

  1. Sheldon, on October 21st, 2009 at 5:53 pm

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

Leave a Reply

Enter Code (required)

  Copyright © 2009 All rights reserved.