views:

408

answers:

1

Here is the problematic part of my jQuery

var tickerWidth = 0;
var padding = 10;
firstList.find('li').each(function() {

            $(this).append(' —');
            tickerWidth += $(this).width() + padding;  

           $('body').prepend($(this).width() + '<br />');

        });

firstList is a variable that holds an ul element. When I run this in Firefox, I correctly get the widths calculated and printed to my page. However, in Safari, I get the width much narrower - about the width it would be had the &mdash; not been inserted... is this some sort of race condition?

Is there any way to combat this? Perhaps loop through first and insert the html entity, and then loop through again to calculate width?

Thanks

EDIT

I did loop through first, insert the html entity, and then do another loop, but the values are still incorrect...

I've also tried outerWidth() but it hasn't helped.

+1  A: 

Okay, I've got it to calculate it correctly, though it's a bit ugly.

Instead of append()ing the entity, I insert it like so

        $(this).html($(this).html() + ' &mdash;');

This works fine.

alex
an odd bug to be sure. You might want to submit this behaviour to the jquery development mailing list
Jonathan Fingland
Go ahead and accept your own answer so that this question doesn't show up as *unanswered* in the site.
ichiban
@ichiban - you must wait 48 hours before you can accept your own answer.
alex