jq- element operation

## content to read and write:

$("#id").html()
$("#id").text()
$("#id").val()


## properties to read and write:
$ ( "# the above mentioned id") attr ( 'title', 'default') to write.
$ ( "# The above mentioned id") prop ( "attrName", "value").

$ ( "# id"). prop ( "attrName") read
$ ( "# id"). removeAttr ( "attrName") Delete property


## Modify Style:

Add existing inline style
$ ( "# id"). AddClass ( "className") // Adds the specified class name $ ( "# the above mentioned id"). Attr ( "class", "className")
$ ( "# the above mentioned id ") .removeClass (" className ") // remove the specified type, if the parameter is omitted, the attribute value represents a class empty $ (" # id "). removeAttr (" class ")

. $ ( "# Id") toggleClass ( "className") // combination of user behavior, to achieve dynamic switching current class name if there is an element of the specified class name is removed;. Does not exist, add

Increasing inline style:
. $ ( "ID #") CSS ( 'Color', 'Red') single

$ ( "# Id") css. ({ 'Color': 'red', 'font-size': '20px'}) of a single or multiple

$ ( "# Id"). Css ( 'display', 'none') # ele.style.display = 'none' hidden elements


## adding elements:
var = H2 $ $ ( '<H3> </ H3>')

$ ( "# Id"). Append ($ h2) increased to $ ( "# id") inside the final surface

$ ( "# Id"). Prepend ($ h2) increased to $ ( "# id") inside the front

$ obj.after (newObj); // add siblings in the back of the $ obj
$ obj.before (newObj); // add a sibling in front of $ obj


$ ( "# Id"). Remove ($ h2) removing elements

Guess you like

Origin www.cnblogs.com/chenlulu1122/p/11888860.html