1

I am storing all checkboxes what my div has in to a variable, later i am finding disabled from the stored variable, but i am not get proper result, instead if I find separately I am getting proper result..

what why i am not find the disabled from my stored variable?

here is my code:

  var   checkedBoxes = $(".locale-container .panel ul li").find("input:checkbox"),
            disabledBoxes = checkedBoxes.find("input:checkbox:disabled"); // not getting

But "disabledBoxes" not getting result from checkBoxes.

In case if I do like this:

 var    checkedBoxes = $(".locale-container .panel ul li").find("input:checkbox"),
            disabledBoxes = $(".locale-container .panel ul li").find("input:checkbox:disabled"); // it works 

so how can i filter or get the appropriate checkboxes from stored variable?

Thanks in advance

2
  • Which Version of jQuery are you using? Commented Oct 3, 2013 at 9:36
  • jquery 1.9.1, currently i am using. Commented Oct 3, 2013 at 9:45

2 Answers 2

1

You have to do this way:

var $parent = $(".locale-container .panel ul li"),
    checkboxes = $parent.find("input:checkbox"),
    disabledBoxes = $parent.find("input:checkbox:disabled"); // NOW YOU GET IT

Try this and see if it solves the issue.

You were not getting the disabled checkboxes because of the context of the selector:

here:

$(".locale-container .panel ul li").find("input:checkbox")

You have got the checkboxes in this "var checkedBoxes" and you were trying to see disabled in this context, means you were checking if checkboxes has disabled checkboxes.

Solution is:

Take a parent then find the input type checkboxes as required.

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

Comments

0

Check for the disabled attribute. You could achive this using has attribute selector in jQuery.

var disabledBoxes = $(".locale-container .panel ul li")
                     .find("input:checkbox[disabled]")

or with has()

   checkedBoxes.has("[disabled]")

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.