Created
July 27, 2013 23:53
-
-
Save randyjensen/6096774 to your computer and use it in GitHub Desktop.
Native JS for jQuery Functions
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
//----Append HTML elements---- | |
/* jQuery */ | |
$(document.body).append("<div id='myDiv'><img src='im.gif'/></div>"); | |
/* native equivalent */ | |
var frag = document.createDocumentFragment(); | |
var myDiv = document.createElement("div"); | |
myDiv.id = "myDiv"; | |
var im = document.createElement("img"); | |
im.src = "im.gif"; | |
myDiv.appendChild(im); | |
frag.appendChild(myDiv); | |
document.body.appendChild(frag); | |
//----Prepend HTML elements---- | |
// same as above except for last line | |
document.body.insertBefore(frag, document.body.firstChild); | |
//----Adding a class------ | |
/* native equivalent */ | |
el.classList.add("someClass"); | |
//----Removing a class----- | |
/* native equivalent */ | |
el.classList.remove("someClass"); | |
//----Does it have class--- | |
/* native equivalent */ | |
if(el.classList.contains("someClass")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment