tags:

views:

158

answers:

2

i have a div tag

<div id="openfrag">
 <script language="JavaScript" src="http://ad.uk.doubleclick.net/adj/BA_HOME/HP_Public_MSB; dcopt=ist;sz=728x90,468x60;tile=1;lan=en;ord=1265795605?" type="text/javascript"></script>
</div>

above script tag is third party url that may returns either image or flash object or any other of any size.. how to determine dynamic width and height occupied by div tag using jquery ?

i tried $("#openxfrag").width() ,but it always return the same width that is defined in css

+1  A: 

Check the width after the content has been loaded into it. You can check the width, or the outerWidth:

$("#openfrag").width();
$("#openfrag").outerWidth();

outerWidth includes padding and borders.

If you're setting a default width with CSS, you may consider removing that (as it overrides the natural width) or replacing it with min-width instead (assuming the future width will be larger).

Jonathan Sampson
+1  A: 

i tried $("#openxfrag").width() ,but it always return the same width that is defined in css

Why wouldn't it? If you're assigning it a width in the CSS, then that's the width it'll have! If you want its width to be dictated by its contents, you'll have to avoid specifying a width... and you'll have to make it shrink-wrap the contents.

Only then can you expect $("#openfrag").width() to do something useful.

Shog9
+1 Good point catching the css-width fact.
Jonathan Sampson