Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does jQuery 2.0.2 add empty style attribute to body

Tags:

jquery

styles

The new jQuery 2.0.2 adds "style" attribute to the body tag in DOM tree. Is there any specific reason?

Printscreen:

enter image description here

like image 881
Marek Avatar asked Jun 16 '13 11:06

Marek


1 Answers

While this doesn't actually affect anything it's still a valid question.

The reason is this code:

// Workaround failing boxSizing test due to offsetWidth returning wrong value
// with some non-1 values of body zoom, ticket #13543
jQuery.swap( body, body.style.zoom != null ? { zoom: 1 } : {}, function() {
    support.boxSizing = div.offsetWidth === 4;
});

This is just a test for boxSizing support. jQuery.swap() is described in the source as:

A method for quickly swapping in/out CSS properties to get correct calculations.

body.style.zoom != null ? { zoom: 1 } : {} returns zoom: 1 if body.style.zoom is not null and an empty object if it is. The returned value is then applied to the body element which is why it has an empty style tag.

like image 120
Joe Avatar answered Oct 16 '22 05:10

Joe