Jump to content

Getting CSS property values using the DOM


sbortman

Recommended Posts

Dear JavaScript forum folks -I am having difficulty identifying a method whereby I can get the value of a CSS property value for a tag.I would like to get the value of a tag's background-image value (e.g. the url string) forthe purpose of obtaining the image's naturalWidth and naturalHeight. I believe this is possible becausewhen I useMozilla Foxfire's firebug add-on, I can see the image's actual dimentions whenever I hover over the value (url string) of the background property in the style tab pane.Any suggestions?Thanks in advance,Calhoon

Link to comment
Share on other sites

you will have to create an image element, create an onload function to retrieve the natural size, and then change the source to the url obtained through the css background-image. CSS does not track the natural sizes of background images like the browser does for <img tags>.you might be able to get away with killing the onload function by applying the .src to the url twice. this could guarantee that the image is loaded,

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...