Ticket #8429 (closed bug: wontfix)
:empty discrepancy between IE and Chrome
| Reported by: | monkeyboyluke@… | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | 1.next |
| Component: | selector | Version: | 1.5.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
I tested the following code on: Google Chrome 6.0.472.63 and Internet Explorer 8.0.6001.18702
The :empty selector gives different results depending on the browser. In IE an object with whitespace is treated as empty and in Chrome an object with whitespace is not treated as empty. I think the internet explorer version is a more helpful implementation of :empty.
Change History
comment:1 Changed 2 years ago by rwaldron
- Priority changed from undecided to high
- Status changed from new to open
- Component changed from unfiled to selector
comment:2 follow-up: ↓ 3 Changed 2 years ago by john
Unfortunately we really need to defer to the spec here (which is that whitespace makes something not empty): http://www.w3.org/TR/css3-selectors/#empty-pseudo
Thus we would need to feature detect what's going on in IE and have it fall back to the old engine.
comment:3 in reply to: ↑ 2 ; follow-up: ↓ 5 Changed 2 years ago by monkeyboyluke@…
Replying to john:
Unfortunately we really need to defer to the spec here (which is that whitespace makes something not empty): http://www.w3.org/TR/css3-selectors/#empty-pseudo
Well. JQuery docs actually define :empty as an element without children. I think what you are saying about CSS standards should mean that a text node counts as a child even if it is just whitespace. Which got me to thinking. Must be the whitespace isn't coming back as a child element. Sure enough, the :text object shows the same bug. http://jsfiddle.net/c5FwK/
comment:4 Changed 22 months ago by dmethvin
I know everyone may like the idea of jQuery hiding this difference, but my feeling on this is wontfix due to the high cost of doing the checking. We'd need to look through all the children and see if they consist of only whitespace text nodes.
In most cases it would be possible to fix this by ensuring that there is no whitespace in empty markup.
comment:5 in reply to: ↑ 3 Changed 21 months ago by dgalvez@…
Replying to monkeyboyluke@…:
Replying to john:
Unfortunately we really need to defer to the spec here (which is that whitespace makes something not empty): http://www.w3.org/TR/css3-selectors/#empty-pseudo
Well. JQuery docs actually define :empty as an element without children. I think what you are saying about CSS standards should mean that a text node counts as a child even if it is just whitespace. Which got me to thinking. Must be the whitespace isn't coming back as a child element. Sure enough, the :text object shows the same bug. http://jsfiddle.net/c5FwK/
Indeed, in ie8 the span innerHTML property is empty and childNodes is reporting there are no children nodes. So there is no way to distinguish between "<span></span>" and "<span> </span>" in this browser.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

This is not just in Chrome. Tested in Chrome, FF, Opera
http://jsfiddle.net/rwaldron/6y964/
One or the other behaviour should be in parity for all.