Search code examples
jqueryliveaddclass

How to use addClass with .live change


I'm using jquery 1.6.1.When I want to use addClass with live change, it doesn't work. please look at my example: http://jsfiddle.net/mr_seven/Mp8zc/1/

$("#qty").live('change', function() {
    if ($(this).val() == '1'){
        jQyery('#card_2').addClass('takhfif');
    } else {
        jQyery('#card_2').removeClass('takhfif');
    }
});

Solution

  • you have typo for selector. it should be jQuery not jQyery:

    $("#qty").live('change', function() {
     if ($(this).val() == '1'){
         jQuery('#card_2').addClass('takhfif');
      } else {
         jQuery('#card_2').removeClass('takhfif');
     }});
    

    Working Fiddle