0

I am facing a weird issue. I am not able to access the checkbox to be disabled using jquery. Here is the code snippet:

HTML

<td class="checkbox1 col5">
    <input type="checkBox" 
           class="checkbox {{contractorInfo.contractorID}}" 
           ng-click=" massUpdateMainCtrl.offboardContractor(contractorInfo,$index)" 
           id="{{$index}}" 
           ng-disabled="massUpdateMainCtrl.disableCheckBoxAlreadyAddedToMassUpdate({{contractorInfo.contractorID}})" 
           ng-checked="massUpdateMainCtrl.disableCheckBoxAlreadyAddedToMassUpdate({{contractorInfo.contractorID}})"> 
    <label for="{{$index}}"></label>
</td>

CSS

input[type=checkbox] {
   display: none;
}

.checkbox1 label {
    border: 1px solid #c0c0c0;
    height: 15px;
    width: 15px;
    max-width: 100%;
    margin-bottom: 0px;
    font-weight: bold;
    vertical-align: middle!important;
}

JQuery:

$(".checkbox").attr('disabled', 'disabled');

Problem here is I am not able to disable the checkbox using jquery.

Please help.

0

5 Answers 5

2

Assuming you have jQuery > 1.6, then you must use .prop() instead of .attr()

$(".checkbox").prop('disabled', true);

As per http://api.jquery.com/attr/ : "To retrieve and change DOM properties such as the checked, selected, or disabled state of form elements, use the .prop() method."

Sign up to request clarification or add additional context in comments.

2 Comments

Tried using .prop but with no luck.
Can you post a JSFiddle with it not working please? I see no reason why it shouldn't, it's the standard way of doing this.
1

Try using 'prop' instead attr,

$(".checkbox").prop('disabled', true);

1 Comment

Edited my ans, Sorry for mistake.
0

You can use this attribute

ng-disabled="!d"

so, using javascript :

$(".checkbox").attr('ng-disabled', "!d");

Comments

0

For jQuery 1.6+ use

Use the new .prop() function:

$("input.group1").prop("disabled", true);
$("input.group1").prop("disabled", false);

And for jQuery 1.5 and below use

$("input.group1").attr('disabled','disabled');

Comments

0

It seems you're using jquery and angular to control your interface, so I don't think it's a good idea, some people may not agree with my point of view, but I recommend that you use just one of these frameworks, in this case only angular. Try to use ng-disabled to accomplish what you want.

For further understanding visit: Angular docs

2 Comments

have used ng-disabled but my view refreshes with new data everytime so the ng-disabled doesnt works that time around.
Problem is that since I have a label for syntax for the checkboxes and have designed the checkbox diffrently with CSS and the original checkbox styled to display:none, I am unable to disable the new labelled checkbox using jquery

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.