问题
Possible Duplicate:
What is the new proper way to use a child selector with a context node in jQuery?
From the jQuery docs:
Note: The $("> elem", context) selector will be deprecated in a future release. Its usage is thus discouraged in lieu of using alternative selectors.
http://api.jquery.com/child-selector/
What would be an alternative selector
for this?
回答1:
$(context).children('elem')
also $("> elem", context)
is deprecated, but $(context+" >elem")
and $("parent>child")
are not
回答2:
$('parent').children('childrenelements')
Is my guess :)
But as the other poster said, its only searching directly for childs in a context.
回答3:
For example, if the context is an element, you would use the selector for that element instead of specifying it as context. So instead of:
var main = $('#Main');
var mainDivs = $('> div', main);
you could use:
var mainDivs = $('#Main > div');
回答4:
I just came across the same issue, I was in the middle of a function and none of the above really helped me. .find seemed to do the trick. This is an example oif how it was useful:
$('selectedcontext').first(function(){
// perform operations on selectedcontext for ex:
if($(this).hasClass('someclass')){
$(this).find('textarea').val();
}
});
来源:https://stackoverflow.com/questions/7833558/child-selector-deprecated