0

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.

1
  • How would you approach the problem and how is that approach not delivering? Commented Oct 13, 2009 at 11:35

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.