Learn JQuery's html () & val () & CSS_DOM operations step by step
Set and obtain HTML, text, and value
Read and set the HTML content of an element: html (). This method can be used for XHTML, but not for XML documents.
Read and set text content in an element: text (). This method can be used for both XHTML and XML documents.
Read and set the value in an element: val () --- this method is similar to the value attribute in JavaScript. for the text box, drop-down list box, single comment this method can return the value of the element (multiple select box can only return the first value ). if you select multiple drop-down lists, an array containing all selected values is returned.
<! Doctype html public "-// W3C // dtd html 4.01 // EN" "http://www.w3.org/TR/html4/strict.dtd">
Use the val () method
<! Doctype html public "-// W3C // dtd html 4.01 // EN" "http://www.w3.org/TR/html4/strict.dtd">
Common node traversal methods
Obtain a set of all child elements that match an element: children (). This method considers only child elements, not any child elements.
Obtains the set of peer elements next to the Matching Element (but only one element in the Set): next ()
Obtains the set of peer elements adjacent to the Matching Element (but only one element in the Set): prev ()
Obtain all peer elements before and after matching elements: siblings ()
Style operations
Obtain the class and set the class: class is an attribute of the element. Therefore, you can use the attr () method to obtain the class and set the class.
Append style: addClass ()
Remove style: removeClass () --- delete all or the specified class from the matched element
Switching style: toggleClass () --- controls repeated switching of a style. If the class name exists, delete it. If the class name does not exist, add it.
Determines whether a style exists: hasClass () --- determines whether the element contains a class. If yes, true is returned; otherwise, false is returned.
CSS-DOM operation
Get and set the style attribute of the element: css ()
Get and set element transparency: opacity attribute
Obtain and set the element height, width: height (), width (). when setting the value, if only a number is passed, the default unit is px. if you want to use another unit, you need to pass a string, for example, $ ("p: first "). height ("2em ");
Obtains the relative displacement of an element in the current window: offset (). The returned object contains two attributes: top and left. This method is only valid for visible elements.
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">