One, jquery selector:
1. jquery element Selector
$ ("P.text")//Select all <p> elements of class= "text"
$ ("P#text")//Select all <p> elements of id= "text"
2. jquery attribute Selector
$ ("[href]")//Select all elements with an href attribute. $ ("[href= ' # ']")//Select all elements with an HREF value equal to "#". $ ("[href!= ' # ']")//Select all elements with an HREF value that is not equal to "#". $ ("[href$= '. jpg ']")//Select all the elements with an href value ending with ". jpg".
3. JQuery CSS Selector
$ ("P"). CSS ("Background-color", "Red"); Always forget to enclose red quotes!!!
Ii. Events:
$ (document). Ready (function () {
Some code
})
Ready means that the document structure has been loaded (not including non-text media files such as pictures), and is relative to onload, which indicates that all elements, including pictures and so on, are loaded.
$ (selector). Click (function () {//some code})
Click is a more common event that triggers or binds a function to the clicked event of the selected element. There are also Dbclick (double-click), MouseOver (hover), focus (get focus), and so on.
Iii. Obtaining content and attributes (text (), HTML (), Val (), attr ())
1. Text ()-Sets or returns the text content of the selected element
Similar to the InnerText property in JavaScript, it can be used to read or set the text content of an element.
<p><strong>hello World</strong></p>alert ($ ("P"). text ()); Hello World
2, HTML ()-Sets or returns the contents of the selected element (including HTML tags)
Similar to the innerHTML property in JavaScript, it can be used to read or set HTML content in an element.
<p><strong>hello World</strong></p>alert ($ ("P"). html ()); <strong>hello world</strong>
3, Val ()-Sets or returns the value of a form field
Similar to the Value property in JavaScript, it can be used to set or get the value of an element.
<p>name: <input type= "text" name= "user" value= "Hello World"/></p>alert ($ ("[type= ' text ']"). Val ()); Hello World
4, attr ()-for getting, setting property values
<p id= "P1" name= "Content" >good Night</p>alert ($ ("#p1"). attr ("name")); Content
$ (selector). attr (attribute,value)//Set property value
$ ("img"). attr ("width", "180");
jquery Learning Notes