$("input").attr({ value: "", title: "Please enter a value" });



Description

This sets the value of all <input> elements to the empty string, as well as sets The jQuery Example to the string Please enter a value.

Syntax

Here is the simple syntax to use this method −

selector.attr(value:inputValue, title:inputTitle)

Parameters

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

  • value − This is the CSS property of the matched element.

  • inputValue − This is the value of the property to be set.

  • title − This is the CSS property of the matched element.

  • inputTitle − This is the value of the property to be set.

Example

Following example would sets the value of all <input> elements to the empty string, as well as sets The jQuery Example to the string Please enter a value.

Live Demo
<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() {
            $("input").attr({ value: "", title: "Please enter a value" });
         });
      </script>
   </head>	
   
   <body>
      <div>
         <input type = "text" id = "result1" title="The jQuery Example" value = "sample" ></input><br/><br/>
         <input type = "text" id = "result2" title="The jQuery Example" value = "sample" ></input>
      </div>
   </body>	
</html>

This will produce following result −

jqueryexamples_attributes.htm
Advertisements