It depends how much control you have over the HTML.  

If you have control over the HTML, one simple solution is to write the width
in another attribute of the image - something that is not re-interpreted by
IE 7.

E.g.

img src="example.jpg" width="100" hwidth="100" 

and then read the value of hwidth instead of width.  

Otherwise, you can get the HTML of whatever contains your IMG tag, and then
use some regular expressions parse out the value of width.


Adrian Rudman wrote:
> 
> 
> Just out of interest how did you work around that? I have been
> battling this problem for a couple of days now!
> 
> On Mar 26, 2:30 am, nabrown78 <nabrow...@gmail.com> wrote:
>> Aha! The problem was that the li elements which contained the images
>> were set to display:none in the CSS. I guess I can work around that.
>>
>> On Mar 25, 10:47 am, nabrown78 <nabrow...@gmail.com> wrote:
>>
>> > Hi All, I have the following code:
>>
>> > $('#slides img').each(function(i){//calculate margins and wrap
>> >                 var this_img = $(this);
>> >                 var imgMargin = Math.round((550 -
>> (this_img.attr("width") + 35))/2)
>> > + 5;
>> >                 this_img.wrap('<div class="wrap0" style="margin-left:'
>> + imgMargin +
>> > 'px"><div class="wrap1"><div class="wrap2"><div class="wrap3"></div></
>> > div></div></div>');
>> >                 $('#content').append('<p>'+imgMargin+'</p>');
>> >         });
>>
>> > On this page:http://www.colleenkiely.com/testLayout2003-2006.htm
>>
>> > In Firefox and Safari the margin is correctly set. In IE7, the margin
>> > is calculated as if this_img.attr("width") were 0. The html markup has
>> > the height and width of each img set explicitly:
>>
>> >  http://www.colleenkiely.com/site_images/2.jpg  > width="507" alt="Dog
>> with Egg Hat (#2)" />
>>
>> > I am using the latest JQuery - 1.3.2.
>>
>> > Any insight into this mystery sincerely appreciated.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/IE7-returning-0-for-attr%28%22width%22%29-on-an-img-with-width-set-tp22705651s27240p23328732.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to