3

I have a slide show. I want to change my slideshow's wrapper class height and width according to the the current images height and width for that I need to get image<> src load using jquery, I tried following to get image src change event but it is not working,

$('.classname img').load(function(){
});
Prasad
  • 1,783
  • 5
  • 22
  • 26

3 Answers3

1

Try using attr() method, to specify attribute for src property.

Setter

$('.classname img').attr('src','YourImageLocation');

getter

var imgUrl=$('.classname img').attr('src');
Ravi Gadag
  • 15,735
  • 5
  • 57
  • 83
  • actually ravi, I tried that also but then it is not calling my $(document) method so I removed it and left it with above only.I only want to get src change event. – Prasad Jan 07 '13 at 05:34
1

You can easily get image height and weight using width() and height(). Anyway, see this - http://jsfiddle.net/xdcj5/ i hope this will help you.

if you need get src attribute of image then you can try like this -

var imgLink = $('img').attr('src');

If even not working then try using live function http://api.jquery.com/live/

HADI
  • 2,829
  • 1
  • 26
  • 26
0

try

$('.classname img').attr('src', 'image.jpg').load(function() {  
  console.log("image loaded");
});  

here is a SO question that might help jQuery event for images loaded

Community
  • 1
  • 1
Dakait
  • 2,531
  • 1
  • 25
  • 43