- Joined
- Jan 18, 2013
- Messages
- 73
- Points
- 8
I don't want to use jQuery for this purpose just for expanding or collapsing a <div> becuase it will load pretty weight, how can I expand and collapse a <div> using javascript?
<script language="javascript">
function toggle() {
var ele = document.getElementById("toggleText");
var text = document.getElementById("displayText");
if(ele.style.display == "block") {
ele.style.display = "none";
text.innerHTML = "Read more";
}
else {
ele.style.display = "block";
text.innerHTML = "Hide";
}
}
</script>
<a id="displayText" href="javascript:toggle();">Read more</a>
<div id="toggleText" style="display: none">Are you trying to find a way to hide and show your content? These codes above shows a simple yet elegant way of toggling your content and toggling the control text via Javascript and styling.</div>