In the previous section, the jQuery selector shows examples of how to select HTML elements. The key point is to learn how the jQuery selector accurately selects the elements you want to apply. The jQuery element selector and attribute selector allow you to use the Tag Name and attribute name... syntaxHighlighter. all (); jQuery selector in the previous section, we show some examples about how to select HTML elements. The key point is to learn how the jQuery selector accurately selects the elements you want to apply. The jQuery element selector and attribute selector allow you to select HTML elements by Tag Name, attribute name, or content. The selector allows you to operate on HTML element groups or individual elements. In html dom terminology, selector allows you to operate a DOM element group or a single DOM node. JQuery element selector jQuery uses the CSS selector to select HTML elements. $ ("P") Select
Element. $ ("P. intro") select all class = "intro"
Element. $ ("P # demo") select all id = "demo"
Element. JQuery attribute selector jQuery uses an XPath expression to select an element with a given attribute. $ ("[Href]") selects all elements with the href attribute. $ ("[Href = '#']") select all elements with an href value equal. $ ("[Href! = '#'] ") Select all elements with an href value not equal. $ ("Your href00000000'.jpg ']") select all elements whose href values end with ". jpg. The jQuery CSS selector can be used to change the CSS attributes of HTML elements. The following example changes the background color of all p elements to red: instance $ ("p" ).css ("background-color", "red ") the jQuery selector instance Selects all elements of * $ ("*") # id $ ("# lastname") id = "lastname. class $ (". intro ") all elements of class =" intro "$ (" p ") All
Element. class. class $ (". intro. demo") All class = "intro" and class = "demo" elements: first $ ("p: first") first
Element: last $ ("p: last ")
Element: even $ ("tr: even") All even numbersElement: odd $ ("tr: odd") All odd numbersElement: eq (index) $ ("ul li: eq (3)") Fourth Element in the list (index starts from 0): gt (no) $ ("ul li: gt (3) ") list the elements whose index is greater than 3: lt (no) $ (" ul li: lt (3) ") list the elements whose index is less than 3: not (selector) $ ("input: not (: empty)") All input elements not empty: header $ (": header") All title elements-: animated all animation elements: contains (text) $ (": contains ('w3school ')") contains all elements of the specified string: empty $ (": empty") all elements of nodes without child (element: hidden $ ("p: hidden") All hidden
Element: visible $ ("table: visible") all visible tables s1, s2, s3 $ ("th, td ,. intro ") All elements with matching Selection [attribute] $ (" [href] ") all elements with href attributes [attribute = value] $ ("[href = '#']") the value of all href attributes is equal to the value of "#" element [attribute! = Value] $ ("[href! = '#'] ") The value of all href attributes is not equal to that of the" # "element [attribute $ = value] $ (" [href?#'.jpg '] ") the values of all href attributes include ". jpg "End Element: input $ (": input ") AllElement: text $ (": text") All types = "text"Element: password $ (": password") All types = "password"Element: radio $ (": radio") All types = "radio"Element: checkbox $ (": checkbox") All types = "checkbox"Element: submit $ (": submit") for all types = "submit"Element: reset $ (": reset") All types = "reset"Element: button $ (": button") All types = "button"Element: image $ (": image") All types = "image"Element: file $ (": file") All types = "file"Element: enabled $ (": enabled") All activated input elements: disabled $ (": disabled") All disabled input elements: selected $ (": selected ") all selected input elements: checked $ (": checked") All selected input Elements