Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Internet Explorer apply CSS to "invalid" elements?

This works in chromium (and I assume every other major browser)

-html-

<invalid></invalid>

-css-

invalid {
    color: red;
}

<invalid> represents an invalid element (not part of the html standard)

here is an example: http://jsfiddle.net/myhonor/4H7Hj/

But when I try this in IE, it doesn't work.

why is this and is there a way fix this (is it a DTD thing?)

like image 457
Samuel Avatar asked Apr 08 '26 13:04

Samuel


1 Answers

That's just the way Internet Explorer works, up to and including version 8. To fix it, just call document.createElement with the name of the invalid element:

document.createElement('invalid');

Here's your updated jsFiddle. It's the same idea as all those HTML5 shivs you see. And, as everyone else has already suggested, writing valid HTML is usually the best solution :)

like image 77
Ry- Avatar answered Apr 10 '26 04:04

Ry-



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!