Orangeman555
Orangeman555

Reputation: 1181

jQuery input .val() or .text()? Both work. .text() safe?

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

Answers (1)

.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

Related Questions