innerHTML

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

innerHTML

Post 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
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post 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
Post Reply