Can I optimize this IE6 double padding & margin fix by using jQuery selectors/filters instead?
Here is some code that I adapted to fix IE6's double padding & margin issue:
// Apply double padding & margin fix for IE6
if ($.browser.msie && parseInt($.browser.version) < 7) {
var elements = self.common.$开发者_运维百科body.find("*").get();
for (var i = 0,
len = elements.length,
$e = $(elements[i]),
cssFloat = $e.css("float"),
cssDisplay = $e.css("display");
i < len;
i++) {
if (cssDisplay !== "none" &&
(cssFloat === "left" || cssFloat === "right")) {
$e.css("display", "inline");
}
};
}
I was thinking it might be faster to do some sort of jQuery.filter()
type operation where I would start off by only selecting those elements that didn't have a display: none;
and that had a float: left;
or float: right;
. Then I could loop through those and simply apply the display: inline;
fix.
Do you think that would work? If so, what would that selector look like? If not or there is a quicker way, please do let me know!
Thanks in advance!
I decided to create a test case on jsPerf.
The results seem to favor my original design. At least that answers the question. If anyone else has another method, I'd love to see it.
精彩评论