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.

 <script>
      alert($("#btnToggleClass").val());
  </script>

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).

 <script>
      $("#btnToggleClass").val("New Value");
  </script>

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: 5197 | Post Order: 38



Write for us






Hosting Recommendations