0

I got a class in css :

img {
    position: relative;
    left: 0;
    top: 0;
}  

and an img in the HTML body. I can move the img with my JQuery/Javascript code:

 $('img').animate({left: "-=20"}, 'fast');    

Now I want to print out the attribute 'left' from my img class. Any Suggestions how to do that? My window.alert($('img').left) does not work. Thanks

Sirko
  • 72,589
  • 19
  • 149
  • 183
FrontMobe
  • 186
  • 1
  • 13

2 Answers2

2

To change a certain css attribute, use

$('foo').css('bar', '42');

To access a certain css attribute, use

$('foo').css('bar');

Thus, to answer your question:

window.alert($('img').css('left'));

To learn more: http://api.jquery.com/css/

taesu
  • 4,482
  • 4
  • 23
  • 41
0

You can use the css method to read the style.

I suppose that you want to get the position after the animation has completed:

$('img').animate({left: "+=20"}, 'fast', function(){
  window.alert($('img').css('left'));
});
Guffa
  • 687,336
  • 108
  • 737
  • 1,005