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:
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.