Page 1 of 1

innerHTML

Posted: Tue Nov 25, 2003 5:54 am
by JayBird
I am using the innerHTML property to change text in a layer.

Here is the code

Code: Select all

<SCRIPT>
function insertScript()
&#123;
    var sHTML="<ul><li class="body">4-cylinder 140hp 4.5 litre.</li><li class="body">6-cylinder 185hp 6.8 litre.</li></ul>";
    ScriptDiv.innerHTML = sHTML;
&#125;
</SCRIPT>
which is executed when this link is clicked

Code: Select all

<a href="javascript:insertScript();">Latest John Deere PowerTech Engines</a>
and the layer that is updated is

Code: Select all

<DIV ID="ScriptDiv"></DIV>
Everthing works okay, i click the link and the text appears. What i want to do though, is when the link is clicked again, the text dissapears. I don't know how to make the link do two different things.

Cheerz

Mark

Posted: Tue Nov 25, 2003 6:26 am
by Nay
I'm using:

Code: Select all

function toggle(box) &#123;

if(document.getElementById(box).style.display == "none") &#123;
document.getElementById(box).style.display = '';
&#125; else &#123;
document.getElementById(box).style.display = 'none';
&#125;

&#125;
To display and hide my DIVs, maybe you can go somewhere along that line? Like:

Code: Select all

if(document.getElementById("ScriptDiv").innerHTML == "") &#123;
// insert the code;
&#125; else &#123;
document.getElementById("ScriptDiv").innerHTML = "";
&#125;
-Nay