Saturday, 10 January 2015

Use Javascript to hide content on a page.

I had cause to require a script to hide and show a map on a page. Javascript for client side convience was required. Here is the code that I used.
Put this code in the head section of your page.
function toggle() {
        var ele = document.getElementById("toggle");
        var text = document.getElementById("display");
    if(ele.style.display == "block") {
        ele.style.display = "none";
        text.innerHTML = "Show Map";
    }
    else {
        ele.style.display = "block";
        text.innerHTML = "Hide Map";
    }
}
This goes in the body of your code.
<a id="display" href="javascript:toggle();">Show Map</a>

No comments:

Post a Comment