Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Explanation >*

Tags:

jquery

I was going through a p rewritten jQuery code . I'm not able to understand the following code .

$('body > *:not(#print-modal):not(script)').clone();
like image 758
user1135534 Avatar asked Sep 11 '26 07:09

user1135534


1 Answers

This selector matches any tag that is:

  • A direct child of <body>
  • Does not have the ID print-modal and
  • Is not a <script> tag.

It then clones all these elements with .clone(), although nothing is done with the clone()d object, which is strange.

A more in-depth explanation:

body > * means "select all elements that are direct descendants of <body>", the wildcard * selecting every tag. Next, the two :not() pseudo-classes filter remove the element with the ID print_modal, as well as any <script> tags.

Reference:

  • jQuery's :not() selector
  • Child and sibling CSS selectors (and another link on the MDN)
  • Universal CSS selectors
like image 159
Bojangles Avatar answered Sep 12 '26 21:09

Bojangles