Robert Gagliano Robert Gagliano - 16 days ago 5
CSS Question

jquery removeAttr('class') still retaining elements of the class

I am struggling with the removeAttr('class') and removeClass() functions in jquery.

removeAttr('class') OR removeClass();


I have three buttons, of which I would like 2 to be disabled (unclickable) when information is entered into a input text form field.

I have entered my current code into the following jsfiddle link:

http://jsfiddle.net/robgagliano/9ttfkw5t/

You will see from the example, the css is changing however the buttons are not disabling (i.e they are still clickable).

Any guidance is greatly appreciated.

Answer

Use keyup event, and a delegated event listener

$(document).ready(function(){

  $("#user-input1").on('keyup change', function() {
      if ($(this).val() != '')
          $("#id2,#id3").removeClass('on');

      else if ($(this).val() == '')
          $("#id2,#id3").addClass('on');;
  });

    $("body").on("click",".on", function(){ // delegated event listener
        var tab_id = $(this).attr('value');
        $('.select').removeClass('currentttt');
        $(".options").hide();
        $(".table1").show();
        $("#option4").show();
        $("#"+tab_id).show();
        $(this).addClass('currentttt');

    });
});

JSFiddle demo

Comments