jQuery: background-position and Internet Explorer
jQuery (at least up till version 1.2.6) has a problem with Internet Explorer when asking the background-position of an object.
In the other A-grade browsers, you get 2 values (in px or %) representing respectively the x-position and y-position of the element. In Internet Explorer (6 and 7) you get undefined.
The problem is that IE doesn't know what
You can now use this jQuery plugin to get the background-position of an element:
There is a ticket open in the jQuery Bugtracker about this isue, but it is weird that such a simple problem isn't fixed already.
$('h1:first').css('background-position');background-position is, it only knows 2 other calls: background-position-x and background-position-y. Here is a slice of JavaScript code to handle this problem.
(function($) {
jQuery.fn.backgroundPosition = function() {
var p = $(this).css('background-position');
if(typeof(p) === 'undefined') return $(this).css('background-position-x') + ' ' + $(this).css('background-position-y');
else return p;
};
})(jQuery);$('h1:first').backgroundPosition();