jquery function call multiple times on class name need to prevent -
i need call js function on list item click when event fires calls event number of times
js
$('.first').click(function () { //remove previous class , add clicked tab items.removeclass('current'); $(this).addclass('current'); $('#v-nav>div.tab-content').hide().eq(items.index($(this))).show(); window.location.hash = $(this).attr('tab'); });
html
<div id="v-nav"> <ul> <li tab="tab1" class=" first cmcltabcss current "> <span class="spn_inercom"> commercial sector </span> <span class="tab1current spn_nmbr"> </span></li> <li tab="tab2" class="first dmtabcss"><span class="spn_inerdip">diplomatic missions</span><span class="tab1currentd spn_nmbr"></span></li> <li tab="tab3" class="first govtabcss"><span class="spn_inergov">government sector</span><span class="tab1currentg spn_nmbr"></span></li> <li tab="tab4" class="first wrldtabcss"><span class="spn_inerwld">outside kingdom</span><span class="tab1currentw spn_nmbr"> </span></li> <li tab="tab5" class="first imgtabcss"><span class="spn_inerimg">images</span><span class="tab1currenti spn_nmbr"> </span></li> <li tab="tab6" class="first"><span class="spn_inernews">news archive</span><span class="tab1currentn spn_nmbr"> </span></li> <li tab="tab7" class="first ppltabcss"><span class="spn_inerindual">site users</span><span class="tab1currentindual spn_nmbr"></span></li> </ul> </div>
the code provided correct. check out here: jsfiddle
there must other part of code triggers click
handler multiple times.
for problem described code job (omitted specific code clarity):
$('.first').click(function () { $('.first').removeclass('current'); $(this).addclass('current'); window.location.hash = $(this).attr('tab'); });
Comments
Post a Comment