Robert Gagliano Robert Gagliano - 1 year ago 65
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:

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 Source

Use keyup event, and a delegated event listener


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

      else if ($(this).val() == '')

    $("body").on("click",".on", function(){ // delegated event listener
        var tab_id = $(this).attr('value');


JSFiddle demo

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download