javascript - Bootstrap ignore style modifications -
i'm developing simple webpage using twitter bootstrap.
at sidebar have 3 buttons. each of buttons calls function show 1 div , hide others.
the html code like:
<div> <div class="row" id="general" style="display:none"> text1 </div> <div class="row" id="medication" style="display:none"> text2 </div> <div class="row" id="diet" style="display:none"> text3 </div> </div>
and 1 of js functions hide/show divs:
function showgeneral(){ document.getelementbyid('general').style.display = 'block'; document.getelementbyid('medication').style.display = 'none'; document.getelementbyid('diet').style.display = 'none'; }
i update code @chaoticnadirs answer still not work. here code @ bootply
the problem function works once finish divs became hidden again (as default).
i feel problem in transition due twitter bootstrap framework.
does how solve this?
bootstrap provides .hidden
class. can use rather display style hide , show elements.
check bootply example: http://www.bootply.com/uy7khe3nw7
html:
<button class="btn btn-default" id="show-general">show general</button> <div> <div class="row hidden" id="general"> text1 </div> <div class="row" id="medication"> text2 </div> <div class="row" id="diet"> text3 </div> </div>
js:
$("#show-general").on('click', showgeneral); function showgeneral(){ $('#general').removeclass('hidden'); $('#medication').addclass('hidden'); $('#diet').addclass('hidden'); }
edit:
in new example firing event on <div>
click inside <a>
tag. can prevent default action:
js:
$('#showgeneral').on('click', showgeneral); function showgeneral(e){ e.preventdefault(); $('#general').removeclass('hidden'); $('#medication').addclass('hidden'); $('#diet').addclass('hidden'); $('#workout').addclass('hidden'); }
here's new bootply: http://www.bootply.com/3rkabpx6d0
Comments
Post a Comment