Add CSS to iframe elements using the .css - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:IFrame

Description

Add CSS to iframe elements using the .css

Demo Code

ResultView the demo in separate window

<html lang="en">
   <head></head>
   <body translate="no"> 
      <div class="text-editor"> 
         <iframe class="text-field" id="text-field" src="about:blank" contenteditable="true"> </iframe> 
      </div> 
      <script>
      window.onload = function() {
  var frameElement = document.getElementById("text-field");
  var doc = frameElement.contentDocument;
  doc.body.contentEditable = true;
  doc.body.innerHTML = doc.body.innerHTML + '<style>body {color:red;}</style>'
}
    // ww w .  ja v a2  s  .  c o  m
      </script>  
   </body>
</html>

Related Tutorials