An example of the difference between a neutron element and a descendant element in jquery

  • 2020-03-30 02:31:42
  • OfStack

Learn about jQuery selectors today:

JQuery selectors are divided into basic selectors, hierarchical selectors, filter selectors, form selectors.

Basic selector: id,class, tag name, *, element combination (div,span,p.m. Class)

Level selector:

Difficulty: the difference between jquery neutron elements and descendant elements
Descendants, all descendants of the current element,
Child elements, which are subsets of the current elements, don't count any further down.

Specific analysis can be referred to:
 
<div>This is <strong>very</strong> important.</div> 
<div>This is <em>really <strong>very</strong></em> important.</div> 

So that's HTML. After running is seen in the browser

This is very important.
This is really very important.

This style, in order to see the effect, we might as well try to add CSS color to try it

If you run $("div strong").css("color","red"); This is to make strong, the descendant of div, red. After the operation is

This is very important.
This is really very important.

If $("div> Strong "). The CSS (" color ", "blue"); I'm going to change strong, the child of div, to blue. After the operation is

This is very important.
This is really very important.

Can be commonly understood in this way, for example, there is a family of three generations, grandpa, father and you, so the child element of grandpa is your father, and your father is also the descendant element of grandpa, and you are just the descendant element of grandpa.

Related articles: