Skip to content

Instantly share code, notes, and snippets.

@phloe
Created April 27, 2012 13:49
Show Gist options
  • Save phloe/2509412 to your computer and use it in GitHub Desktop.
Save phloe/2509412 to your computer and use it in GitHub Desktop.
escaping selector fun
div {
margin: 10px;
min-height: 20px;
padding: 2px;
}
span {
margin: 2px;
}
div {
background-color: lightgrey;
}
/* Valid */
#\# {
background-color: cyan;
}
#\. {
background-color: cyan;
}
#\\ {
background-color: cyan;
}
#\: {
background-color: cyan;
}
#\[ {
background-color: cyan;
}
.\. {
background-color: cyan;
}
.\# {
background-color: cyan;
}
/* Invalid */
#\ {
background-color: yellow;
}
[\[=\]] {
background-color: yellow;
}
[\]=\=] {
border: 1px solid red;
}
/* Invalid - no IE */
[\==\=] {
background-color: red;
color: #FFF;
}
<h4>Valid - but weird</h4>
<div id=#>id=#</div>
<div id=.>id=.</div>
<div id=\>id=\</div>
<div id=:>id=:</div>
<div id=[>id=[</div>
<div class=.>class=.</div>
<div class=#>class=#</div>
<hr/>
<h4>Invalid - but somehow working</h4>
<div id=" ">id=" "</div>
<div [=] ]==>[=] ]==</div>
<hr/>
<h4>Invalid - doesn't work in IE</h4>
<div ===>===</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment