Javascript Style How to - Get style text








Question

We would like to know how to get style text.

Answer


<!DOCTYPE html>
<html>
<body>
  <style>
    .foo {<!--from   ww  w  .  ja  v a  2s  . c  o m-->
      color: red
    }
    </style>
<script type='text/javascript'>

    var el = document.getElementsByTagName("style")[0];
    console.log(el.innerHTML);

</script>
</body>
</html>

The code above is rendered as follows: