2015. 7. 16. 18:09

.val( function(index, value) )

.val( function(index, value) )

function(index, value)A function returning the value to set.

This method is typically used to set the values of form fields. 

For <select multiple="multiple">elements, multiple s can be selected by passing in an


The .val() method allows us to set the value by passing in a function. 

As of jQuery 1.4, the function is passed two arguments, the current element's index and its

current value:

$('input:text.items').val( function(index, value) {
  return value + ' ' + this.className;

This example appends the string " items" to the text inputs' values.

Trackback 0 Comment 0