Jquery content and attributes

text(), html() and val()

method Obtain Set up Description
text() $("Selector").text() $("Selector").text("Hello world!") Set or return the text content of the selected element
html() $("Selector").html() $("Selector").html(" Hello world! ") Sets or returns the content of the selected element (including HTML markup)
val() $("Selector").val() $("Selector").val("RUNOOB") Set or return the value of a form field

attr() prop()

For the inherent attributes of the HTML element itself, use the prop method when processing.
For our own custom DOM attributes of HTML elements, we use the attr method when processing them.

method grammar Set up Description
attr() $("Selector").attr() $("Selector").attr("href","www.runoob.com") Used to get our own custom DOM attributes
prop() $("Selector").prop() $("Selector").prop("href","www.runoob.com") Used to get the inherent attributes of the element itself

Guess you like

Origin blog.csdn.net/weixin_44640323/article/details/112972764