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>

Example – Hide Me

Inspiration / Original script.

0 Be the first to like this.