How to return the color of the text with JavaScript?

JavascriptWeb DevelopmentFront End Scripts

To return and set the text color, use the JavaScript color property.

Example

You can try to run the following code to return the text color with JavaScript −

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <h2>Heading 2</h2>
      <p id="myId" style="color:green;">Demo Text</p>
      <br>
      <button type="button" onclick="display()">Click to get color</button>
      <script>
         function display() {
            alert(document.getElementById("myId").style.color);
         }
      </script>
   </body>
</html>
raja
Published on 27-Feb-2018 15:35:48
Advertisements