javascript - How to trigger the toggle on one click instead of two -
i using simple toggle this:
   function toggle_visibility(id) {    var e = document.getelementbyid(id);    if(e.style.display == 'block')       e.style.display = 'none';    else       e.style.display = 'block'; } and html this:
 <div id="income">  <h5 onclick="toggle_visibility('incometoggle');">income</h5>  <div id="incometoggle">     <h6>income total</h6>   </div>    </div>   at moment, need click twice on heading div close. how can make close 1 click?
first check condition display none
function toggle_visibility(id) {     var e = document.getelementbyid(id);     if (e.style.display == 'none') e.style.display = 'block';     else e.style.display = 'none'; } jquery
  $("h5").click(function() {     $("#incometoggle").toggle();    }); 
Comments
Post a Comment