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

后端 未结 5 871
慢半拍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 13:56

    you could use h1.text() or h1.html() which map to innerText and innerHTML respectively.

    As for val() that maps to input.value.

    Using the jquery equivalents gives you cross-browser compatibility, although that's probably more of a historic relic. New browsers probably implement these features the same way.

    As a general rule: value is used on input elements, innerHTML on non-input fields.

提交回复
热议问题