let's say I want to build an HTML button with a text on it, like "Click me!" - and then access it in my JS app. I could set the text of that button as a node value, or as innerText, for example (I know, there are also innerHtml and InnerTextContent, but those are irrelevant for me in this case) - What I did not yet fully understand is - When do I use "innerText", when do I use "value", to set this text, preferrably?
I do know and (think I) understand the difference between them both, but I don't know yet when to prefer the one or the other. Is there anything like a rule of thumb for this issue? Any great dis-/advantages?
Thank you very much in advance!
Edit: Thanks for your answers so far, wow that was fast! :) Just to clarify things and avoid misunderstandings - as I said above, my question is not about InnerHTML or TextContent or all the other possible ways to get text on a button.
I am really only referring to the different usecases between "value" and "innerText" with that goal to set a visible button text as "Click Me!" right on that button. I am looking for a best practice rule for this, you could say. :)
I think, TJ Crowder answered this really well, thank you TJ and of course, thank you anybody else for your time and help! :) As I am new to this platform, I am not yet allowed to give you guys a like. So FEEL it please. :D Thanks!
You only use
value
on form controls (input
,button
,select
, andtextarea
). For any other element, if you want its text, usetextContent
orinnerText
(or, depending on your use case,innerHTML
).The only tricky one there is
button
, which is the only form control that has both avalue
and text. Thevalue
of abutton
is the value that will be submitted if that button submits the form it's in. The text is what the user sees as the button caption. Here's an example: