Created
May 6, 2013 16:02
-
-
Save bjankord/5526074 to your computer and use it in GitHub Desktop.
Mapping $ to document.querySelector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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