1. Get the attributes of an element
Gets and sets properties using the Attr method of jquery, removing the attribute using the Removeattr method.
Syntax: $ (selector). attr (attribute)
Here's an example: $ (' img '). attr (' src ')//Get the SRC attribute under the IMG element
2. Setting the attributes of an element
Since we can all get the attributes of the element, we will generally operate on the acquired element.
Syntax: $ (selector). attr (Attribute,value)
For example, we can set a div title, id, and so on.
// set the div's ID $ (' #div1 '). attr (' id ', ' div2 ');
Of course, the interesting thing about jquery, of course, is that it supports setting multiple properties.
// set multiple properties $ (' #div1 '). attr ({ ' href ': ' http://www.baidu.com ', ' title ': ' Baidu ' });
3. Modifying element content
There are 3 ways to get the content of an element:
(1) text (): Sets or returns the text content of the selected element
(2) HTML (): Sets or returns the contents of the selected element (including HTML tags)
(3) Val (): Sets or returns the value of a form field
The biggest difference between text and HTML is that text returns only the textual content of the element, and HTML returns the parsed content of the HTML.
Val returns the contents of the form.
4. Dynamically Create Content
Syntax: $ (HTML)
Remember the first jquery you started with? That's the dynamically created Div.
(3) jquery-manipulating the DOM with jquery