Skip to content

Instantly share code, notes, and snippets.

@zachleat
Last active August 19, 2018 12:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zachleat/fbc60c7ff5349a6ab81e to your computer and use it in GitHub Desktop.
Save zachleat/fbc60c7ff5349a6ab81e to your computer and use it in GitHub Desktop.
Differences between jQuery().find and querySelectorAll

Scope

$.fn.find scopes selectors to the context element by default and querySelectorAll requires using the :scope pseudoelement selector.

// 0 results
jQuery("body").find("html div").length;

// Lot of results
document.body.querySelectorAll( "html div" ).length;

See also:

"> element" selectors

jQuery("body").find("> div"); // Works
document.body.querySelectorAll( "> div" ).length; // Error

Custom Pseudoselectors

  • :checked
  • :selected

Thanks to:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment