Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
81
rated 0 times [  86] [ 5]  / answers: 1 / hits: 25952  / 8 Years ago, tue, december 27, 2016, 12:00:00

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 $(textarea).val();



Instead if I have a h1 element, I must use $(h)[0].innerHTML;



Why is this the case? h1.val()/textarea.innerHTML do not work


More From » jquery

 Answers
236

.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()


[#59545] Sunday, December 25, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
irvingcarloe

Total Points: 677
Total Questions: 109
Total Answers: 96

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
irvingcarloe questions
Wed, Mar 31, 21, 00:00, 3 Years ago
Tue, Aug 4, 20, 00:00, 4 Years ago
Fri, Jul 3, 20, 00:00, 4 Years ago
;