10

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

1 Answer 1

10

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.

1
  • Actually it does for display:table type body
    – Kevin Wang
    Dec 12, 2013 at 0:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.