views:

875

answers:

4

I have a bug in IE8 when trying to get a property from css for an element with background image.

el.css({ 'background-position': "10px 10px"}); //set some 
alert(el.css("background-position")); //get the value

In Opera, FF, Chrome, Safari works I get "10px 10px". Not in IE8 where I get undefined. I opened a bug report, but until then what do you think it will be a good workaround this problem. How should I get this values in some another way?

+1  A: 

If you alert the background-property, then you'd also get the position. A very bad workaround, but the first I could think of...

alert(el.css("background")); //url(some/url/to/image.jpg) no-repeat 10px 10px

And then you'd have to just get out the numerical values that are followed by "px"

peirix
You can't predict the unit will be pixel itself.
rahul
technically this should work but it doesn't because the property was set with css function and is not added to the real css but inserted dynamicly in the style attribute
Elzo Valugi
+3  A: 

Hey, good question!

I've never tried this but i found that by requesting the positions individually u get a result, so:

alert(el.css("background-position-y")); //get the y value
alert(el.css("background-position-x")); //get the x value

then you can combine the two :)

Wayne Austin
this one works in IE, Safari, Chrome but not in FF :(
Elzo Valugi
+3  A: 

this should help

it links to jquery ticket 2462 which is also interesting

Dan F
the dextrose link was ok and works. good suggestion. Thanks.
Elzo Valugi
A: 

I will finally parse them from:

alert(el.attr('style')); // this seems to work in all browsers
Elzo Valugi