Rate this script:  I Love it  /   I Hate it

JavaScript automagically hide and show an HTML tag (DIV, P, whatever)


Code


<a href="javascript:viewMore('two');" id="xtwo">... more</a>
<p>I see one.</p>
<p id="two" style="display:none">I see two.</p>

function viewMore(div) {
        obj = document.getElementById(div);
        col = document.getElementById("x" + div);
       
        if (obj.style.display == "none") {
                obj.style.display = "block";
                col.innerHTML = "... less";
        } else {
                obj.style.display = "none";
                col.innerHTML = "... more";
        }
}
 

 

 
JavaScript automagically hide and show an HTML tag (DIV, P, whatever) scripts | JavaScript automagically hide and show an HTML tag (DIV, P, whatever) snippet | JavaScript automagically hide and show an HTML tag (DIV, P, whatever) example | JavaScript automagically hide and show an HTML tag (DIV, P, whatever) tutorial | JavaScript automagically hide and show an HTML tag (DIV, P, whatever) code