Reputation: 1181
As title mentions, I have a choice to use .val()
or .text()
on inputs that I am looping through.
Although .val('sometext')
is technically right, .text('sometext')
allows me to loop through span elements too (which are used as prompts if form-filling is invalid.
Is it ok to use .text()
instead?
Upvotes: 0
Views: 341
Reputation: 57105
.val() works on form elements (or any element with a value attribute?) like textbox,select,radio buttons,checkbox
etc.
.text() works with span,div,a etc.
tags
Upvotes: 2