Over a million developers have joined DZone.

JavaScript Automagically Hide And Show An HTML Tag (DIV, P, Whatever)

·
If you want to hide or show an HTML tag using JavaScript, you can use the function below. It also changes the name of the link.

Here's the HTML code:

... more

I see one.

Here's the JavaScript code: 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"; } }
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}