JQuery element.children(".class") returns null
There must be something obvious that I'm doing wrong, but I'm not seeing it. I have obtained a reference to a DOM element using JQuery. It has the following innerHTML (from the javascript debugger):
<INPUT type=hidden name=Item.ItemIndicators[0].Indicator.Strategies[0].Description>
<INPUT style="DISPLAY: none" class=checkbox value=00000000-0000-0000-0000-000000000000 type=checkbox name=Item.ItemIndicators[0].Indicator.Strategies[0].Id>
<INPUT value=-1 type=radio name=Item.ItemIndicators[0].Indicat开发者_JAVA技巧or.Strategies[0].Weight>
<INPUT value=1 type=radio name=Item.ItemIndicators[0].Indicator.Strategies[0].Weight>
<INPUT type=text150 name=Item.ItemIndicators[0].Indicator.Strategies[0].Description>
However, when I do the following, I get null.
var child = myElement.children(".checkbox");
Is "checkbox" not an allowed class name, maybe?
Thanks!
For Matt, full code below:
var strategies = parent.children("div.strategy");
for (var i = 0; i < strategies.length; i++)
{
//strategies[i] is the element in question w/the innerHTML above
var checkbox = strategies[i].children(".checkbox"); //returns null
...elided...
}
Additional Info: if I do the following, I get "object doesn't support this property or method":
var strategy = strategies[i];
var children = strategy.children(); //object doesn't support this property or method
Not sure of the terminology to use here, but from the properties displayed in the debugger, and from this error, it seems like the strategy object is not seen by jquery as a jquery object but rather just as an dom element (i.e., it's missing the [0] property). Still, it's odd that the line "strategies[i].children(".checkbox")" does not throw the same exception.
You need to make sure that you're calling to jquery methods from jquery wrapped sets / jquery object.
You can achieve that simply by changing your code for something like
$(parent).children("div.strategy").each(function(i){
var checkboxes = $(this).children(".checkbox");
...yourstuff ...
//'this' refers to each strategy dom element
}) ;
Children is also a property for DOM elements, so that could be causing some confusion.
精彩评论