troubleshooting Question

Append CSS to iframe

Avatar of hankknight
hankknightFlag for Canada asked on
5 Comments1 Solution867 ViewsLast Modified:
I want to be able to change the CSS used in an iframe from a link.

My iframe does not have a name, only an id.

My code below does NOT work.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="">
<script type="text/javascript">
function addEditorCSS (child,css) {
  var ifr = getElementById(child);
  var headID = ifr.document.getElementsByTagName("head")[0];
  var cssNode = ifr.document.createElement("link");
  cssNode.type = "text/css";
  cssNode.rel = "stylesheet";
  cssNode.href = css; = "screen";
<h1>Hello World</h1>
<iframe src="2.html" id="elm1_ifr"></iframe>
<hr />
<a href="javascript:('elm1_ifr','')">Change CSS</a>

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros