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

Thanks for your help Patrick - I'm a complete newbie when it comes to
javascript and DOM, but you and David have helped get me on the right track
here. I've gotten this to work - the problem was in my implementation.
Thanks again, both of you.

Jonathan



Patrick Garies wrote:
> 
> 
> nimblehost wrote:
>>  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"); } </script>
>>
>>  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.
> 
> I just tested this in Mozilla Firefox 3.0.1 by changing a |link| 
> element’s |media| attribute value from |print| to |all| and found no 
> issues. I checked Firebug 1.2.0b6 and noticed that the DOM had been 
> modified as expected.
> 
> I don’t see any issues in your shown code assuming that you’re sending 
> your XHTML via the MIME type text/html. The problem must be elsewhere in 
> your code. You may want to verify that the script is executed /after/ 
> your |link| element is created in the DOM.
> 
> Your code could use some improvements nevertheless:
> * In XHTML served via an XML MIME type, the |getElementsByTagNameNS| 
> method should be used instead of |getElementsByTagName|.
> * You should declare your variables (i.e., |var x = 0|).
> * The MIME type text/javascript is deprecated in favor of the MIME types 
> application/javascript and application/ecmascript. Unfortunately, 
> neither are supported in Windows Internet Explorer up to version 7.
> 
> — Patrick Garies
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Using-DOM-to-replace-media-attribute-in-the-link-tag-on-page-load-tp18531235p18593298.html
Sent from the w3.org - www-dom mailing list archive at Nabble.com.

Received on Tuesday, 22 July 2008 16:45:59 UTC