Forum Moderators: not2easy

Message Too Old, No Replies

Universal Selector in IE

selects more than expected?

         

SuzyUK

7:54 am on Mar 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Old news perhaps, but new to me and I haven't seen it here, I don't think

I knew there was something about the universal selector but never bothered looking, however I stumbled upon it in travels this weekend.

the Universal Selector {*} is truly Universal in IE

All versions inc IE7 are affected, as far as I can tell, The universal selector is usually used to select all children of a specific element but in IE it also selects <!-- HTML Comments --> as well some others, which might be unexpected

sample:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>IE Universal Selector Oddity</title>
<style type="text/css">
body div * {
display: block; /*this makes it visible for proof demo */
border: 3px double #008;
padding: 20px 10px;
background: #ffe;
height: 80px;
}
p {margin: 0;}
</style>
</head>
<body>
<h1>IE Universal Selector Oddity</h1>
<div>
<p>The Universal Selector '*' selects HTML Comments and some other unexpected elements - it is possible to apply some styles to it.
-- In IE you should see 3 main boxes, the second one - which is an HTML comment - is empty. --
The box around the text in the bottom box is generated by it selecting the &lt;br&gt; element
</p>
<!-- This is an HTML comment -->
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.<br></p>
</div>
</body>
</html>

Not major perhaps but just filing for posterity ;)

Suzy

Robin_reala

9:43 am on Mar 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This reminds me of the 'duplicate characters [positioniseverything.net]' bug in IE6. In that it was shown that the bug was caused by either comments or elements with display:none. That suggests that comments are treated as non-displayed ELEMENT_NODEs (in DOM parlance), not COMMENT_NODEs. Something to investigate via the DOM?