Home  >  Article  >  Web Front-end  >  Example introduction to the difference between child elements and descendant elements in jquery_jquery

Example introduction to the difference between child elements and descendant elements in jquery_jquery

WBOY
WBOYOriginal
2016-05-16 16:53:451178browse

Learn jQuery selectors today:

jQuery selectors are divided into basic selectors, hierarchical selectors, filter selectors, and form selectors.

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

Hierarchical selector:

Difficulty: jquery The difference between child elements and descendant elements.
Descendants are all descendants of the current element. They are counted.
Child elements are a subset of the current element. Going further down will not be counted.

For specific analysis, please refer to:

Copy code The code is as follows:

This is very important.

This is really very important.


The above is html. After running, you will see

This is very important.
This is really very important.

style in the browser. In order to easily see the effect, we might as well try to use Add css color to try

If you run $("div strong").css("color","red");, it will turn the descendant element strong of the div into red. After running, it is

This is very important.
This is really very important.

If you run $("div>strong").css("color","blue") ; is to turn the strong sub-element of the div into blue. After running, it is

This is very important.
This is really very important.

can be understood in a popular way, for example, there are three generations of a family living under the same roof, grandfather, father and you. Your grandfather's child element is your father, and your father is also your grandfather's descendant element, and you are just your grandfather's descendant element.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn