1 point

How to change any attribute of a HTML element


dashboard

Sun Jan 26 2020 21:05:50 GMT+0000 (UTC)

Posted 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_copy Copy

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"