-1

Im trying to override a class of the bellow label :

<label id='wishlist' class="btn btn-default btn-custom-small ">                                                                  
    <input type="checkbox" class="searchfilter collapse" value="my_wishlist" name="my_wishlist" data-toggle="button"> My Wishlist                                             </label> 

I can do it with the bellow code snipets

 $('#wishlist').removeClass('btn-custom-small').addClass('btn-custom-small active');    

But the code stops working as soon as it is called in a click event:

$("#wishlist").click(function() {
                $('#wishlist').removeClass('btn-custom-small').addClass('btn-custom-small active');
            });
ronline
  • 1,974
  • 1
  • 15
  • 20
  • 1
    why are you removing and adding the same class? So is the element on the page when you add the click? `console.log($("#wishlist").length);` – epascarello Aug 25 '16 at 00:49
  • Works fine: https://jsfiddle.net/czsa6akt/ Do you have code that actually demonstrates the problem? – David Aug 25 '16 at 00:52
  • http://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements – epascarello Aug 25 '16 at 01:35

1 Answers1

0

I have sorted out the issue by moving the code to ajax success handler.

success: function(data){
if( filters == 'my_wishlist' )  $('#wishlist').removeClass('btn-custom-small').addClass('btn-custom-small active');
ronline
  • 1,974
  • 1
  • 15
  • 20