Toggle, hide, collapse your html content
July 31, 2008
obj is the <div> id
<script type='text/javascript'>
function toggle(obj){
var e=document.getElementById(obj);
if(!e)return true;
if(e.style.display=="none"){
e.style.display="block"
} else {
e.style.display="none"
}return true;
}
</script>
in your markup
<a href='#' onClick="toggle('mydiv')">Toggle</a>
<div id='mydiv' style="display:none">
Lorem ipsum dolor sit amet, consectetur
adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna
aliqua. Ut enim adminim veniam.
<div>
EDIT: sorry for the wrong code.
its now updated
Posted in Code Repository, Javascript | 3 Comments »
Tags: collapse div, contract, expand, hide html, hiding your div, paminggalan, toggle
Theme: Treba by Phu. Blog at WordPress.com.
August 9, 2008 at 12:55 am
“in your markup” should be:
;
Lorem ipsum dolor sit amet, consectetur
adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna
aliqua. Ut enim adminim veniam.
error in the closing , you have it as and the starting <div code should assume that it is hidden.
Thanks for posting this, I needed a refresher on the Javascript code.
August 11, 2008 at 2:15 am
thanks for the comment.
i’ve edited my post
April 14, 2009 at 2:54 am
what if i only want the a div close if the word-count of a post is less then 400 words?