1. Get content: Text (), HTML (), Val ()
Three simple and practical jQuery methods for DOM manipulation:
- Text ()-Sets or returns the text content of the selected element
- HTML ()-Sets or returns the contents of the selected element (including HTML tags)
- Val ()-Sets or returns the value of a form field
2. Get Properties: ATRR ()
The JQuery attr () method is used to get the property value.
1) Get the <a> href
$ ("a"). attr ("href")
2) obtained from the defined attribute
<p zhen= "true" > Total </p>
$ ("P"). attr ("Zhen")
Note: The above is the value that returns the selected element, as well as the setting property and value.
1) Set the attributes and values of the selected element.
Syntax: $ (selector). attr (attribute,value)
Usage: $ ("img"). attr ("width", "180"); //Get the width of the image
2) Use the function to set the attribute/value of the selected element
Syntax: $ (selector). attr (attribute,function (index,oldvalue))
Usage: $ ("img"). attr ("width", function (n,v) {
return v-50;
}); //Reduce the width of the image by 50 pixels
3) set more than one attribute and value for the selected element.
Syntax: $ (selector). attr ({attribute:value, attribute:value ...})
Usage: $ ("img"). attr ({width: "", "Height:"}); Set the width and height of the image
JQuery-Get content and properties