W3C home > Mailing lists > Public > www-dom@w3.org > July to September 2008

Using DOM to replace media attribute in the link tag on page load

From: nimblehost <jhead@hawaii.edu>
Date: Fri, 18 Jul 2008 08:00:47 -0700 (PDT)
Message-ID: <18531235.post@talk.nabble.com>
To: www-dom@w3.org

I've found no references online that address this particular challenge, so I
hope the DOM experts here can point out the mistakes in my code. The
original html I am trying to replace looks like this:

<link rel="stylesheet" type="text/css" media="screen"
href="rw_common/themes/nhmobile/css/screenwidth/variable.css" />

I'd like to change the media attribute to "all" when the page loads so that
it looks like this instead:

<link rel="stylesheet" type="text/css" media="all"
href="rw_common/themes/nhmobile/css/screenwidth/variable.css" />

The code I've come up with is as follows:

<script type="text/javascript">
	var mediaType = document.getElementsByTagName("link");
	for(x=0; x<mediaType.length; x++) {
		mediaType.item(x).setAttribute("media", "all");

Using firebug to check the current tree of nodes shows that the media
attribute remains unchanged. I'm at a loss at how to fix this problem. Any
and all help is greatly appreciated.

Best regards,
View this message in context: http://www.nabble.com/Using-DOM-to-replace-media-attribute-in-the-link-tag-on-page-load-tp18531235p18531235.html
Sent from the w3.org - www-dom mailing list archive at Nabble.com.
Received on Monday, 21 July 2008 08:02:57 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:14 UTC