html - Set class with jquery? -


i have javascript function looks this:

function updatefilterview(){      if(_extrafilterexists){          if($('#f_showf').val() == 1){              $('#extrafilterdropdownbutton').attr('class', "showhideextra_up");             $('#extrafilterdropdownbutton').css("display", "block");              if($('#divcategoryfilter').css("display") == 'none'){                 $('#divcategoryfilter').show('slow');             }             return;          }         else{              if($('#divcategoryfilter').css("display") == 'block'){                 $('#divcategoryfilter').hide('slow');             }              $('#extrafilterdropdownbutton').css("display", "block");             $('#extrafilterdropdownbutton').attr('class', "showhideextra_down");              return;          }     }     else{         if($('#divcategoryfilter').css("display") != 'none'){                 $('#divcategoryfilter').hide('fast');         }         $('#extrafilterdropdownbutton').css("display", "none");     } } 

this triggered following code (from within $(document).ready(function () {):

$('#extrafilterdropdownbutton').click(function () {     if($('#f_showf').val() == 1){         $('#f_showf').val(0);     }     else{         $('#f_showf').val(1);     }      updatefilterview(); }); 

the html easy:

<div id="divcategoryfilter">...</div>  <div style="clear:both;"></div> <div id="extrafilterdropdownbutton" class="showhideextra_down">&nbsp;</div> 

i have 2 problems this:

  1. when panel hidden , press div button(extrafilterdropdownbutton) upper left part of page flicker , panel animated down.

  2. when panel shown , press div button panel hide('slow'), button not change correct class when set in updatefilterview script?

the correct class set on button when hovering it, set following code :

$("#extrafilterdropdownbutton").hover(function() {     if($('#divcategoryfilter').css("display") == 'block'){         $(this).attr('class','showhideextra_up_hover');     }     else{         $(this).attr('class','showhideextra_down_hover');     } },  function() {      if($('#divcategoryfilter').css("display") == 'block'){         $(this).attr('class','showhideextra_up');     }     else{         $(this).attr('class','showhideextra_down');     } }); 

to set class completely, instead of adding 1 or removing one, use this:

$(this).attr("class","newclass"); 

advantage of you'll remove class might set in there , reset how like. @ least worked me in 1 situation.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -