DOM = Document Object model
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
Gets the Property-attr (): $ ("#w3s"). attr ("href"); Set property value: $ ("#w3s"). attr ("href", "http://www.w3school.com.cn/jquery"); Use Object ({" href ":" www "," title ":" http "}) can be set multiple at the same time.
The callback function for text (), HTML (), and Val ():The callback function consists of two parameters: the subscript I of the current element in the selected element list, and the original (old) value Origvalue.
$ ("button"). Click (function () {$ ("#w3s"). attr ("href", function (i,origvalue) { return origvalue + "/jquery";}); });
Add a new HTML content
- Append ()-Inserts the content at the end of the selected element, in the element
- Prepend ()-Inserts the content at the beginning of the selected element, in the element
- After ()-Inserts the content after the selected element,
- Before ()-insert content before selected element
Delete element/content
The JQuery Remove () method deletes the selected element and its child elements.
The JQuery Empty () method deletes the child elements of the selected element.
The JQuery Remove () method can also accept a parameter that allows you to filter the deleted element. That is, only those with parameters are deleted.
JQuery operation CSS (CSS parameters)
- AddClass ()-adds one or more classes to the selected element
- Removeclass ()-deletes one or more classes from the selected element
- Toggleclass ()-switch operation to add/Remove classes for selected elements
- CSS ()-Sets or returns the style properties. Returns ( first ) The value of the specified CSS property, setting the style css ({"PropertyName": "Value", "PropertyName": "Value",...});
Width/Height:
- Width (),height (): Gets the $ (document). width (); $ (window). width (); Set:$ ("#div1"). Width (+). Height (+);
- Innerwidth (),innerheight () returns the width height of the element (including padding)
- Outerwidth (),outerheight () returns the width and height of the element ( including padding and borders )