views:

133

answers:

2

In every browser, Win/Mac, Chrome, Safari, Firefox, Opera, IE6, and IE7 they ALL get the following console output:

352

254

But in IE8 I get:

414

434

454

474

Here is my JS/jQuery code:

$('#top-breadcrumbs').children('a').each(function(i){
    if(!$(this).hasClass('permanent')){
        if(permItemWidth+rmItemWidth > $('#top-breadcrumbs').width()){
            $(this).addClass('removed');
            rmItemWidth = rmItemWidth-$(this).width()+20;
        }
    }
});

The log code i have above is writing the NEW rmItemWidth value after its been reset in that 2nd if

A: 

I posted here, and then i finally figured it out playing with the code. So, the change? Well no actual code had to be changed haha IE8, actually, i think did it right... oddly enough:

Before:

$(this).addClass('removed');
rmItemWidth = rmItemWidth-$(this).width()+20;

After:

rmItemWidth = rmItemWidth-$(this).width()+20;
$(this).addClass('removed');

Because "this" is removed in that first line in the before, so technically, it would have no width. Thats why it was only adding 20 each time... is IE8 actually doing it correctly and no one else?!

Oscar Godson
+1  A: 

Without seeing the entire code, an expected outcome cannot be determined.

Instead, I suggest writing valid HTML, valid CSS, and figuring out what it is that needs to be done to obtain the desired calculation.

It is typical of a jQuery programming style to put something like this:

$('#top-breadcrumbs').width()
  • inside the body of a function that is called in a loop.

That approach you have chosen using jQuery is very inefficient.

Garrett