Skip to content

Instantly share code, notes, and snippets.

@bjankord
Created May 6, 2013 16:02
Show Gist options
  • Save bjankord/5526074 to your computer and use it in GitHub Desktop.
Save bjankord/5526074 to your computer and use it in GitHub Desktop.
Mapping $ to document.querySelector
<h1>From: http://flippinawesome.org/2013/05/06/5-things-you-should-stop-doing-with-jquery/</h1>
<div class="container">
<ul>
<li id="pink">Pink</li>
<li id="salmon">Salmon</li>
<li id="blue">Blue</li>
<li id="green">Green</li>
<li id="red">Red</li>
</ul>
</div>
<script>
// Note that IE 8 only supports CSS 2.1 selectors for querySelector.
// create a global '$' variable
window.$ = function(selector) {
return document.querySelector(selector);
};
(function() {
// select item1 by id and change it's background color to salmon
var item = $("#salmon").style.backgroundColor="salmon";
console.log(item);
}());
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment