JQuery syntax is compiled for the selection of HTML elements. You can perform some operations on the elements. The basic syntax is: $ (selector ). the $ action () symbol defines the jQuery selector to query and find the HTML element jQuery's action () for execution... syntaxHighlight jQuery syntax is compiled for the selection of HTML elements. You can perform some operations on the elements. The basic syntax is: $ (selector ). the $ action () symbol defines the jQuery selector "Query" and "search" the action () of the HTML element jQuery to execute the operation example for the element $ (this ). hide ()-hide the current element $ ("p "). hide ()-hide all paragraphs $ ("p. test "). hide ()-hide all paragraphs of class = "test" $ ("# test "). hide ()-hide all element document readiness functions with id = "test". You may have noticed that all jQuery functions in our instance are in a document ready function: $ (document ). ready (function () {--- jQuery functions go here ----}); this prevents the document from running jQuery code before it is fully loaded (ready. If you run the function before the document is fully loaded, the operation may fail. The following are two examples: Try to hide a nonexistent element to obtain the size of an incomplete loaded image. 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 the first 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 "); more selector instance syntax descriptions $ (this) Current HTML element $ ("p") All
Element $ ("p. intro") of all class = "intro"
Element $ (". intro ") All class =" intro "elements $ (" # intro ") id =" intro "first element $ (" ul li: first ") each
The first
- Element $ ("Your href00000000'.jpg ']") All ". href attribute at the end of jpg "$ (" div # intro. all class = "head" elements in head ") id =" intro"