p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Professional (http://p2p.wrox.com/forumdisplay.php?f=215)
-   -   retrieve attribute values from CSS(from class) (http://p2p.wrox.com/showthread.php?t=57551)

anujrathi May 7th, 2007 01:23 AM

retrieve attribute values from CSS(from class)
 
Hi experts,
I am facing a problem with stylesheets.
I hav some div in my page. I set their styles using stylesheet(with the help of id ).
Now i have to change their height & width using javscript.
But i am not able to get these values from CSS.

eg. document.getElementById('idname').height or
      document.getElementById('idname').style.height
is not working. first one shows null & later shows undefined.

But if i write these properties in style attribute then i can get it easily by
    document.getElementById('idname').style.height


Pls tell me that is there any way to pick attribute values from class name (means from css)

regards,
Anuj rathi

planoie May 7th, 2007 01:57 PM

As you are finding, style behavior that is dictated by a style sheet is not "readable" in the same way as styles that are applied using the style="..." inline attribute. However, there is usually a way of reading it.

When an element is drawn on the page it always has height and width and other similar properties (even if they are determined automatically by the browser based on the flow of the page versus being assigned specifically by an inline style or a CSS setting). This values are often available by prefixing "offset" to the style in question. Try using something like this:

document.getElementById('idname').style.offsetHeig ht

You can try the "offset" prefix for other values too:

.offsetWidth
.offsetLeft
.offsetTop
etc.

Hope that works for you.

-Peter


All times are GMT -4. The time now is 08:33 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.