jQuery

jQuery Intro

jQuery Intro Quiz

jQuery Intro Exercise

jQuery Basic

jQuery Basic Quiz

jQuery Basic Exercise

jQuery Advance

jQuery Advance Quiz

jQuery Advance Exercise

jQuery Selectors

jQuery Effects

jQuery Events

jQuery Methods and Properties

jQuery Traversing

jQuery CSS and HTML Methods

jQuery val() Method

jQuery val() Method

 

 

The val() method is used to return or set the value attribute of the selected elements. It is used with form elements.

 

For your Information:-

 

  • If used to return, It will return the value of the value attribute of the FIRST matched element.
  • If used to set, It will set the value of the value attribute for ALL matched elements.

 

Syntax:-

 

  1. Its syntax for returning value attribute is:- $(selector).val()
  2. Its syntax for setting value attribute is:- $(selector).val(value)
  3. Its syntax for setting value by function is:- $(selector).val(function(index,currentvalue))

 

Further Explanation:-

 

Parameter Description
value Required. Specifies the value of the value attribute
function(index,currentvalue) Optional. Specifies a function that returns the value to the set.
  • index - Returns the index position of the element in the set
  • currentvalue - Returns the current value attribute of selected elements

Code Explanation

All Tutorials related to jQuery CSS and HTML Methods

All Sections related to jQuery