What is the new proper way to use a child selector with a context node in jQuery?

The reason they are saying:

Note: The $("> elem", context) selector will be deprecated in a future release. Its usage is thus discouraged in lieu of using alternative selectors.

Is due to the comma followed by the context in the selector. E.g. $("> elem") is fine however, $("> elem", context) will be deprecated.

$("> elem", context) is the same as $(context + "> elem").

A correct way of obtaining children and grandchildren is

$("elem").children('.child').children('.grandchild');

or

context.children('.child').children('.grandchild');

or

context.find('> .child > .grandchild');

Leave a Comment