jQuery > Attribute related method

.val() - Get or set the value of an element in jQuery

How to get or set the value of an element in jQuery?

To get an set the value attribute of an html element, val() method can be used.


Above code snippet will alert the value of the element whose id is “btnToggleClass” (in this case it is html button, it will return button text).

      $("#btnToggleClass").val("New Value");

Above code snippet will set the specified value to the html element whose id s “btnToggleClass” (in this case, it will set the text of button to “New Value”).

 Views: 4709 | Post Order: 38

Write for us

Hosting Recommendations