santa
santa

Reputation: 12512

disable form field on checkbox select wih jQuery

I need be able to disable form element and add a class "disabled" in all TDs with class="myToggle". Not sure if I'm doing it right:

$("#myCheck").click(function() {
  $(".myToggle").addClass("disabled").attr("disabled", true);
});

<td><checkbox id="myCheck"> My checkbox</td>
<td class="myToggle"> My label</td>
<td class="myToggle">
    <select>
       <option>option
    </select>
</td>

Can I combine like this?

Upvotes: 0

Views: 555

Answers (3)

Halil &#214;zg&#252;r
Halil &#214;zg&#252;r

Reputation: 15947

$("#myCheck").click(function() {
  $(".myToggle").find("input, select, textarea")
    .addClass("disabled")
    .attr("disabled", true);
});

Upvotes: 2

Harish
Harish

Reputation: 2324

Your Problem is not clear still u may try this and check if i has got some thing to help?

http://jsfiddle.net/CStTZ/5/

Upvotes: 1

user170386
user170386

Reputation:

I believe jQuery has it's own toggle function for elements to show/hide them.

$('.target').toggle();

But what you wrote should work too, since you are trying to operate on a class, and many element can share the same class name at the same time.

Upvotes: 1

Related Questions