Javascript Ajax jQuery Html PHP Example Quiz New MORE

How to remove required attribute to an input box jquery

Example:

<!DOCTYPE HTML> 
<html> 
	<head> 
		<title> 
			Add a required attribute to an input field 
		</title> 
		
		<script src = 
"https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"> 
		</script> 
	</head> 
	
	<body style = "text-align:center;"> 
	
		<p style = "font-size: 15px; font-weight: bold;"> 
			Click on the button to add the required attribute.
		</p> 
		
		Name: <input type="text" name="input_field" /> 
		
		<br> 
		<button id="submit"> 
			click here 
		</button>
			<p id = "GFG_down" style = 
			"color: green; font-size: 20px; font-weight: bold;"> 
		</p> 
		
		<script> 
		  $(document).ready(function(){
           	$("#submit").click(function(){
			 $('input').attr('required', false); 
		     document.getElementById("GFG_down").innerHTML  
                        = "Required attribute enabled"; 
			 });
		  });
		</script> 
	</body> 
</html>		
Run it Yourself »