This time I will bring you a summary of the usage of JQuery $(), what are the precautions when using JQuery $(), the following is a practical case, let's take a look.
Usage of JQuery $(): There are three main types, taking expressions, taking elements, and taking functions.
1, Tag selector$('p'), Class selector$('.myClass'), id selector $('#myId') is relatively simple, not much to say. But there is one thing - there is a difference between $('p>ul') and $('p ul').
$('p>ul') is the direct descendant of
.
So, $('#sId>li') selects all
What is returned here is a jQurey object, an array object. The length of this jQuery object can be obtained with .length().
2. What is in ] is the attribute of the element; it is a
attribute selector
There is no @ in [], which means that what is in [] is the descendant of the element. $('ul li') and $('ul[li]') both return a jQuery array, but their meanings are exactly the opposite. The former is to find all the descendants of
$('th').parent()—— $('td:contains("Henry")').prev()——内容包含有"Henry"的<td>的上一个节点 $('td:contains("Henry")').next()——内容包含有"Henry"的<td>的下一个节点 $('td:contains("Henry")').siblings()——内容包含有"Henry"的<td>的所有兄弟节点
The node that performs the action here is find(...), which is an array Object, the action it takes is "addClass()", and then end() is used. At this time, the returned stuff points to the node pointed to by parent(), that is, the "addClass()" action is performed. The parent node of that array object.
5. To access DOM elements directly, you can use the get(0) method, such as
$('#myelement').get(0), which can also be abbreviated to $('#myelement')[0]
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
How to operate the width and height attributes of the page, visual area, screen, etc.How to use Web Storage storageThe above is the detailed content of JQuery $() usage summary. For more information, please follow other related articles on the PHP Chinese website!