Open
Description
Description
The jQuery documentation for text()
at https://api.jquery.com/text/ states:
The .text() method cannot be used on input elements. For input field text, use the .val() method.
But this is factually incorrect. jQuery allows a text value to be passed to an input, or any other empty tags such as <img />
for that matter. The provided content can instead be visible after the element on the console, as a child, although it will not show in the DOM.
For example, consider the following HTML chunk:
<p><input /></p>
The following code
$('input').text( "Hello" );
will render:
<p><input />Hello</p>
Thus, the statement that ".text() method cannot be used on input elements" is factually incorrect, and maybe should be replaced with ".text() method should not be used on input elements"
Also, it should be added that the text thus provided will be added as a hidden child of the element.
Metadata
Metadata
Assignees
Labels
No labels