views:

33

answers:

3

I have an input box and I want it to be disabled at the same time as hidden to avoid problems when porting my form.

So far I have the following code to hide my input:

        $(".shownextrow").click(function() { 
  $(this).closest("tr").next().show().find('.longboxsmall').hide();
});

This is the input that gets hidden as a result:

 <input class="longboxsmall" type="text" />

How can I also add the disabled attribute to the input??????

+3  A: 

http://api.jquery.com/attr/

$("#example").attr("disabled", "disabled");

A: 

Just use jQuery's attr() method

$(this).closest("tr").next().show().find('.longboxsmall').attr('disabled', 'disabled');
gmcalab
A: 

You can get the DOM element, and set the disabled property directly.

$(".shownextrow").click(function() { 
  $(this).closest("tr").next().show()
          .find('.longboxsmall').hide()[0].disabled = 'disabled';
});

or if there's more than one, you can use each() to set all of them:

$(".shownextrow").click(function() { 
  $(this).closest("tr").next().show()
          .find('.longboxsmall').each(function() {
               this.style.display = 'none';
               this.disabled = 'disabled';
          });
});
patrick dw