views:

114

answers:

1

What is the best possible way using jQuery to give height and width to parent div of an Image.

<div><img src="source.jpg" width="%width" height="%height" /></div>

Please note that , there are more than one tags like this. 3-4 images and DIVS.

thanks in advances.

jQuery solution will be preferred.

+3  A: 

Use the jQuery dimensions.

Add a class to each image:

<div><img class='myImage' src="source.jpg" width="%width" height="%height" /></div>

js:

$(".myImage").each(function(){
  $(this).parent().css( { width: $(this).width(), height: $(this).height() } );
});

That's it.

Gl

Ghommey
Thanks Lazarus :)
Ghommey