JavaScript:- Dynamic change text colour

How to change text colour:-

  • element.style method is used to change as well as assign the css property value.
  • element.style.color is used to set a text color to the specified html element.




Code:-

<!DOCTYPE html> 
<html> 

<head> 
 <meta name="viewport" content="width=device-width, initial-scale=1"> 
</head> 

<body> 

 <div id="t_div">Normal Text</div> 

 <button type="button" onclick="set_color();">Change Color</button> 

 <script> 
  function set_color() 
  { 
   document.getElementById("t_div").style.color = "red"; 
  } 
 </script> 

</body> 

</html>

JavaScript:- Dynamic change text colour JavaScript:- Dynamic change text colour Reviewed by Network security on May 31, 2019 Rating: 5

No comments:

Useful Information

Powered by Blogger.