When do I use .val() vs [removed]?

后端 未结 5 895
慢半拍i
慢半拍i 2020-12-10 13:29

In JQuery when trying to access elements, I see that if I have a form (lets say a textarea), and I want to get the text inside of it, I must use

5条回答
  •  没有蜡笔的小新
    2020-12-10 14:18

    .val() is used to get/replace input elements values in jQuery, alternative in JS is .value.

    innerHTML or jQuery's .html() is used to get/replace the whole markup inside an element, not input elements.

    text() is used almost the same as JS innertHTML, only it gets/replaces the text inside an element, not all the tags etc. It's bassically the equivalent of JS innerText

    Reference links about innerHTML, innerText, val(), text(), html()

提交回复
热议问题