Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#13631 closed bug (duplicate)

CSS "background" not reporting properly in certain browsers

Reported by: tegskywalker@… Owned by:
Priority: undecided Milestone: None
Component: css Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:

Description

If an element has background settings set shorthand, it reports back in Chrome but Firefox and IE report an empty string. It wasn't working for my pages where I was looking to get the values of "background" for an element and even hand coding in the console gives the same results.

My CSS is as follows:

#logo { background:url('images/logo.jpg') no-repeat 0px 0px; float:left; width:200px; height:10px; display:inline; }

For example if I do this in Chrome, Firefox, or IE:

$('#logo').css('background');

Chrome reports:

"rgba(0, 0, 0, 0) url(/images/logo.jpg) no-repeat scroll 0px 0px / auto padding-box border-box"

Firefox and IE just report:

""

If I manually look for "background-image" or "background-position", all browsers report the same.

Is this intentional or a bug?

Change History (3)

comment:1 Changed 6 years ago by gibson042

Component: unfiledcss
Resolution: duplicate
Status: newclosed

Duplicate of #13421.

comment:2 Changed 6 years ago by gibson042

Further information from http://api.jquery.com/css/:

[Retrieval of] Shorthand CSS properties (e.g. margin, background, border) are not supported. For example, if you want to retrieve the rendered margin, use: $(elem).css('marginTop') and $(elem).css('marginRight'), and so on.

comment:3 Changed 6 years ago by tegskywalker@…

I do have one last thing though. When you try to get "background-position" with the CSS selector, it reports in IE9+, Chrome, and Firefox with the value but IE is blank. You have you use the non standard "background-position-x" and "background-position-y" to get those values. Do you think down the road if someone is using IE8 and below and they do "background-position" that jQuery can get the x and y values and combine them to give the same value as the newer browsers?

Note: See TracTickets for help on using tickets.