Bug Tracker

Ticket #10796 (closed bug: fixed)

Opened 3 years ago

Last modified 19 months ago

Bug in IE7 with $('#el').css.('background-position')

Reported by: artkik@… Owned by: mikesherov
Priority: low Milestone: 1.7.2
Component: css Version: 1.7
Keywords: Cc:
Blocking: Blocked by:

Description

Hallo!

I found that $('#el').css.('background-position') is defined as "undefined" in IE7 (maybe in IE8 too, I had no tested yet) with jQuery 1.5+. In jQuery 1.42 it works well!

Here is an exampe code:

<!DOCTYPE HTML>
<html><head>
<meta charset="utf-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
</head>
<body>

  <div id="test" style="background-position:0 0;">text</div>
  <script>
      alert( $('#test').css('background-position') )
  </script>

</body>
</html>

Try to change jquery to 1.42 and it gonna works.

Change History

comment:1 Changed 3 years ago by artkik@…

comment:2 follow-up: ↓ 10 Changed 3 years ago by timmywil

  • Owner set to timmywil
  • Priority changed from undecided to low
  • Status changed from new to assigned
  • Component changed from unfiled to css
  • Milestone changed from None to 1.7.1

 http://jsfiddle.net/timmywil/umXhk/3/

Computed style is undefined and our fallback to uncomputed is not in the codepath because ret is not null.

comment:3 Changed 3 years ago by anonymous

I apologize, but I do not speak English as well. I don't understand your message even whith google translater, because there a lot of hard to translate words. I apologize once again. Can you tall me please how can I get the background-position value with new version of jQuery. Thanks

comment:4 follow-ups: ↓ 6 ↓ 8 Changed 3 years ago by timmywil

Sorry, that was more a message for the bugs team and myself. We plan on fixing this issue for the next release, but it is not a regression because I can't imagine it has worked in any version of jQuery. For now, you can get the background-position of this particular element like this:

 http://jsfiddle.net/timmywil/umXhk/4/

comment:5 Changed 3 years ago by anonymous

Thanks! The second example works

comment:6 in reply to: ↑ 4 Changed 3 years ago by anonymous

Replying to timmywil: Thank you for your tip but with IE6 it only works with inline css, with external css it returns an empty string (instead undefined) :(  http://jsfiddle.net/PMQQN/

comment:7 Changed 3 years ago by timmywil

  • Milestone changed from 1.7.1 to 1.7.2

Bumping to 1.7.2.

comment:8 in reply to: ↑ 4 Changed 3 years ago by superk303@…

Replying to timmywil: The trick for this works well with f*g IE is to use 'background-position-x' and 'background-position-y', please implement it in jquery to prevent writing each time this  http://stackoverflow.com/questions/594870/fix-for-background-position-in-ie Thank you very much !

comment:9 follow-up: ↓ 12 Changed 3 years ago by timmywil

@superk: that's not really related to this ticket. The stackoverflow issue does not have to do with jQuery core.

comment:10 in reply to: ↑ 2 Changed 3 years ago by mikesherov

Replying to timmywil:

 http://jsfiddle.net/timmywil/umXhk/3/

Computed style is undefined and our fallback to uncomputed is not in the codepath because ret is not null.

not the only problem. Getting back a value like "0px 0px" incorrectly triggers the "awesome hack by Dean Edwards".

comment:12 in reply to: ↑ 9 Changed 3 years ago by superk303

Replying to timmywil: You probably didn't red my post correctly, I just wrote that it would be nice that $('.elem').css('background-position') returns a correct string such '10px 10px' instead of undefined or an empty string, with external css on IE6 (and maybe other laters) as you can see on this jsfiddle with IE6 (so IT IS a jquery issue) :  http://jsfiddle.net/PMQQN/ And it can be easily implemented thankfully to the tricks explained at the mentionned stackoverflow question with the properties 'background-position-x' and 'background-position-y' concatened... thanks dudes

comment:13 follow-up: ↓ 14 Changed 3 years ago by timmywil

@super: I don't think you understand. There is no computed background position in your example in IE because there is no background. Retrieving bpx and bpy is unnecessary.

comment:14 in reply to: ↑ 13 Changed 3 years ago by superk303

Replying to timmywil: well ok, I corrected the test :  http://jsfiddle.net/PMQQN/3/ It can be needed to simulate a hover event with the sprite method and so just changing background-position...

comment:15 Changed 3 years ago by mikesherov

  • Owner changed from timmywil to mikesherov

comment:16 Changed 3 years ago by sindresorhus

#10923 is a duplicate of this ticket.

comment:17 Changed 3 years ago by will@…

The problem is that when you request any CSS property that is not set or does not exist in an elements' style, it should return null. Requesting say:

alert($("<div/>").css("thisPropertyDoesNotExist"));

Returns null, but the following:

alert($("<div/>").css("backgroundPosition"));

Causes an internal jQuery error in 1.7.1, and doesn't in 1.6.4

comment:18 Changed 3 years ago by Mike Sherov

  • Status changed from assigned to closed
  • Resolution set to fixed

Fix #10796. Allow IE<9 to retrieve uncomputed styles.

Changeset: 6aa4095ed62e3e37dae4c39c00fb627a3b282307

comment:19 Changed 2 years ago by sindresorhus

#11838 is a duplicate of this ticket.

comment:20 Changed 19 months ago by gpakosz

looks like it doesn't work anymore on 1.9.1

Note: See TracTickets for help on using tickets.