Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

DZone's Guide to

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

·
Free Resource
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:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}