1. Get and set styles
$ ("#tow"). attr ("class") Gets the class attribute with ID tow
$ ("#two"). attr ("Class", "Divclass") sets the class attribute with ID.
2. Append style
$ ("#two"). AddClass ("DivClass2") appends a style to an object with ID: divClass2
3. Remove Style
$ ("#two"). Removeclass ("Divclass") removes the style with the class name Divclass of the object with ID two.
$ (#two). Removeclass ("Divclass divClass2") removes multiple styles.
4. Switch class name
$ ("#two"). Toggleclass ("Anotherclass")//repeat Toggle Anotherclass style
5. Determine if a style is included
$ ("#two"). Hasclass ("another") ==$ ("#two"). Is (". another");
6. Get styles from CSS styles
$ ("div"). CSS ("color") sets the value of the Color property. $ (Element). CSS (Style)
Set a single style
$ ("div"). CSS ("Color", "red")
Set multiple styles
$ ("div"). css ({fontSize: "30px", Color: "Red"})
$ ("div"). CSS ("height", "30px") ==$ ("div"). Height ("30px")
$ ("div"). CSS ("width", "30px") ==$ ("div"). Height ("30px")
7.offset () method
Its function is to get the relative offset of the element in the current window, where the returned object contains two properties, that is, top and left.
Note: Valid only for visible elements.
var offset=$ ("div"). offset ();
var left=offset.left; Get left Offset
var top=offset.top; Get right Offset
8. Position () method
Its function is to get the relative offset of the element relative to the nearest position style property set to relative or absolute's grandfather node, as with offset (), and the object it returns also includes two properties i.e. top and left.
9. ScrollTop () method and ScrollLeft () method
$ ("div"). scrolltop (); Gets the distance from the top of the scroll bar of the element.
$ ("div"). ScrollLeft (); Gets the distance from the left of the scrollbar of the element.
10, the toggle and Slidetoggle methods in jquery can realize the display and hiding of an element. The difference is:
Toggle: The dynamic effect is from right to left. Lateral action.
Slidetoggle: Dynamic effect from bottom to top. The vertical action.
For example, to achieve a tree from bottom to top contraction of the dynamic effect, the use of Slidetoggle is OK.
$ (' input '). attr ("ReadOnly", True)//sets the INPUT element to ReadOnly
$ (' input '). attr ("ReadOnly", False)//Remove the ReadOnly attribute of the INPUT element
$ (' input '). attr ("Disabled", true)//sets the INPUT element to disabled
$ (' input '). attr ("disabled", false)//Remove the disabled attribute of the INPUT element
CSS styles for manipulating elements using jquery (Fetch, modify, and so on)