How to change any attribute of a HTML element

PHOTO EMBED

Sun Jan 26 2020 21:05:50 GMT+0000 (Coordinated Universal Time)

Saved by @_right_away_ #html #javascript #jsfunctions #dom #dommanipulation

<html>	
   
   <input id="contact" name="address">
 
 <script>

    document.getElementById("contact").attribute = "phone";
	
    //ALTERNATIVE METHOD TO CHANGE
    document.getElementById("contact").setAttribute('name', 'phone');	

  </script>

</html>
content_copyCOPY

Both lines 7 and 10 perform the same function. In this example, they are changing the value of the name attribute in the input element from "address" to "phone"