4

I am disabling the ID checkbox using following jquery

jQuery

$('.ColVis_collection button').first().find('input').attr("disabled", true);

html

This code is inside another button, which when clicked gets activated like a dropdown.

<div class="ColVis_collection TableTools_collection" style="display: block; position: absolute; opacity: 1; top: 102px; left: 274px; width: 449px;">
    <button class="ColVis_Button TableTools_Button" style="width: 449px;">
        <span>
            <span class="ColVis_radio">
                <input type="checkbox" checked="checked">
            </span>
            <span class="ColVis_title">
                <span>
                    id
                </span>
            </span>
        </span>
    </button>
    <button class="ColVis_Button TableTools_Button" style="width: 449px;">
        <span>
            <span class="ColVis_radio">
                <input type="checkbox" checked="checked">
            </span>
            <span class="ColVis_title">
                <span>
                    name
                </span>
            </span>
        </span>
    </button>
    .
    .
    .
</div>

The first button with span id gets disabled using the jquery and blurred showing that it is disabled but it can be clicked i.e. checked/unchecked. Am I missing something?

Edit:

I am using jQuery datatables colvis feature, which lets you hide/unhide the table columns

As you can see in this image, the checkbox seems disabled but can be checked/uncheked

Image

3
  • 1
    What version of jQuery are you using? in more recent versions of jQuery .attr("disabled","disabled") should be .prop("disabled",bool) Commented Oct 3, 2013 at 15:19
  • I'm unclear as to what the problem is. In this fiddle (jsfiddle.net/j08691/PBhPJ) the ID checkbox is disabled. Commented Oct 3, 2013 at 15:21
  • @j08691, ya but neither other checkbox can be clicked, but when used with Datatables colvis feature, the checkbox can be checked/unchecked, and Yes by the jQuery I've posted, its seems like its been disabled but can be clicked.. I am using jQuery 1.8 Commented Oct 3, 2013 at 15:37

4 Answers 4

11

Use .prop() instead of .attr() to set the disabled property

$('.ColVis_collection button').first().find('input[type="checkbox"]').prop("disabled", true);

Demo: Fiddle

Attributes vs. Properties

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

Comments

4

try some thing like this:

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

Comments

0

Try adding a read only attribute as well:

$('.ColVis_collection button').first().find('input').attr("disabled", true).attr("readonly", true);

That might sort you out . . .

Comments

0

Didn't figured out what happened. May be I'll look later. Ended up hiding the first button i.e.

$('.ColVis_collection button').first().attr("hidden", true);

Comments

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.