Skip to main content
GameDev.net gamedev.net
🔒 Locked

[web] How to get css(external) values using javascript?

Started by johnnyBravo Feb 15, 2005 at 10:20 PM 1 replies 500+ views
Original Post
johnnyBravo
johnnyBravo
Hi, I want to get the values eg like obj.style.width, from the style sheet. Except the css file is external, so it just returns 0 from what i wrote above. Anyway I tried using: window.getComputedstyle which only works for netscape/firefox and obj.currentstyle which only works for ie. So I was wondering if there are any other ways to get a value from the stylesheet that works with most browsers? For example in a scenario like this: /*css file */ input.textfield {width:5em;} <-- html file --> thanks
Pipo DeClown
Pipo DeClown
This is how you do it:

document.getElementById("giveObjectAnIDFirst").style.width = "15px";
Easca
Easca
Look into the stylesheet collection of the DOM Document Object. Using this you can evaluate the rules in an external style sheet.


If you have Firefox installed you can use the DOM Inspector to browse the &#106avascript objects and see more details about the stylesheet collection.<br/><br/><!--EDIT--><span class="editedby"><!--/EDIT-->[Edited by - Easca on February 17, 2005 1:04:53 PM]<!--EDIT--></span><!--/EDIT-->

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.