php - dynamically handle jquery events -
i have list of main subjects streams. let's art, science, commerce. each main steam there several subjects. such science, subjects mathamatics, bio science , etc.
when user select main stream, want show relevent subjects selected main stream. use jquery pannels. basicaly, when stream checked releveant subjects div toggle.
i main stream , subjects database. can change(dynamic). how handle this?
i used following code. not dynamic.
$("#science").change(function(){ $("#mathas").slidetoggle("fast"); }); $("#bio_cience").change(function(){ $("#b").slidetoggle("fast"); }); $("#pure_maths").change(function(){ $("#cc").slidetoggle("fast"); });
i want make above script dynamic. how proceed?
your html like...
<div id="1sub" class="sub">sub1</div> <div id="2sub" class="sub">sub2</div> <div id="3sub" class="sub">sub3</div> <div id="stream-1" class="stream" style="display:none;">stream 1</div> <div id="stream-2" class="stream" style="display:none;">stream 2</div> <div id="stream-3" class="stream" style="display:none;">stream 3</div>
now,in jquery
$(".sub").click(function(){ var subclicked = $(this).attr('id'); $(".stream").hide(); $("#stream-" + subclicked.substring(0,1)).toggle(); });
Comments
Post a Comment