Differences between text (), html (), val () in js, and jsval
Differences between text (), html (), and val () in js
The text (), html (), and val () methods are used to store values and values of html elements, but they have their own characteristics. text () is used to access html element text content, html () can be used not only to access html element text content, but also to access html content. Val () is used to access the content of input elements.
I. text ()
Var text = $ ("div"). text ();
Console. log (text );
<Div> text </div>
Console: text
Ii. html ()
<Div> <p> text </p> </div>
Var str = $ ("div" pai.html ();
Console. log (str );
Console: <p> text </p>
Iii. val ()
<Input type = "text" value = "text"/>
Var str = $ ("input"). val ();
Console. log (str );
Console: text
Similarities and Differences:
Both text () and html () can be used for element text access, but html () can be used for element text access and Element Node access.
Unlike text () and html (), val () is used to access the content of input nodes.