jQuery basic selector
BeginnerjQuery, in order to learnjQuerybetter systematically, today I specially summarize my learning experience and post it to share with the beginners. Today I mainly summarize the basic selectors ofjQuery. The basic selector of
jQueryis the most commonly used selector injQueryand is also the simplest selector. It mainly uses theID# of the element. ##,CLASS, element tagELEMENT, etc. to find theDOMelement inHTML. In a web page, each ID name can only be used once, and class can be used repeatedly. In jQury applications, you can use these basic selectors to complete most of the work. Let's mainly take a look at their specific implementation process. In order to learn better, we first list an HTML tag code here:
我是一个名为mini的div标签我是一个名为mini的div标签我是一个名为mini的div标签我是一个段落p标签
我是一个行内span标签Then let’s look at the applications of these basic selectors respectively1. ID Selector
Selector:#id
Description:Match an element based on the given id
Return:Single element
Example:
Function:Change the id to mydiv The background color of the element
2. Class selector
Selector:.class
Description:Return elements matching the given class name
Return:Collection elements
Example:
Function:Change the background color of all elements with class mini
3. Tag element
Selector:element
Description:Match elements based on the given element name
Return:Collection elements
Example:
Function:Change the background color of all elements whose element name is
4. All elements*
Selector:*
Description:Change all matching html tag elements
Return value:Collection elements
Example:
Function:Change the background color of all html element tags
5. selector1, selector2,....selectorN
##Selector:selector,selector2,...selectorN
Description:will each The elements matched by the selector are combined and returned together
Return:Collection elements
Example:
Function:Change the background color of the class name mini and paragraph p elements