jQuery Examples - $("button").val("Hello")



Description

This sets the value attribute of every matched element <button>.

Syntax

Here is the simple syntax to use this method −

selector.val(value);

Parameters

Here is the description of all the parameters used by this method −

  • value This is the value to be set to the matched element.

Example

Following example sets the value attribute of every matched element <button>.

<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>		
      <script type = "text/javascript" language = "javascript">	 
         $(document).ready(function() {
            $("button").val("Hello");
         });
      </script>
   </head>	

   <body>
      <div>
         <form name = "sampleForm">
            <button type = "button">Click Me!</button>
         </form>
      </div>
   </body>	
</html>

This will produce following result −

jqueryexamples_attributes.htm
Advertisements