4

Anybody familiar with Sizzle? Is there support for selecting children of cached DOM nodes? Like jQuery:

var body = jQuery('body');
var div = jQuery('#mydiv',body);

10x for your kind help, BR

kidwon
  • 4,448
  • 5
  • 28
  • 45

1 Answers1

6

Use direct child selector with context:

Sizzle( "> *", body);

In fact, I directly copypasted Sizzle source code and this worked, so I don't understand the downvotes:

var body = Sizzle("body");
var childrenOfBody = Sizzle( "> *", body[0]);
Esailija
  • 138,174
  • 23
  • 272
  • 326
  • Isn't that very slow? I can use direct selector, but that's not the point. Anyway thanks for your cooperation I give you +1 for your effort to help – kidwon Jul 26 '12 at 11:24
  • @kidwon By "cached", do you mean assigning the result to a variable like your whole post suggests? – Esailija Jul 26 '12 at 11:26
  • Yes, I mean saving the reference to the node in a variable – kidwon Jul 26 '12 at 11:27
  • @kidwon Ok, so what's the problem then? If you are in pure sizzle, there is no such thing as `.children()` but the selector with context is equivalent. – Esailija Jul 26 '12 at 11:28
  • Maybe the "*" selector fooled some people and they down voted you, I didn't get it the first time either, however I don't like the down arrow when people are trying to help. BR – kidwon Jul 26 '12 at 11:44
  • 2
    +1. (And regarding the downvote - which seems to have been removed now - you've been around SO long enough to know that people downvote correct answers just because they're in a bad mood, or they didn't like your user name, or whatever.) – nnnnnn Jul 26 '12 at 11:55