Created
May 19, 2013 00:41
-
-
Save brimelow/5606230 to your computer and use it in GitHub Desktop.
jQuery DOM - Native equivalents
This file contains 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 some HTML elements---- | |
// jQuery | |
$(document.body).append("<div id='myDiv'><img src='im.gif'/></div>"); | |
// native equivalent (BAD WAY) | |
document.body.innerHTML += "<div id='myDiv'><img src='im.gif'/></div>"; | |
// native equivalent (BEST WAY) | |
var frag = document.createDocumentFragment(); | |
var myDiv = document.createElement("div"); | |
myDiv.id = "myDiv"; | |
frag.appendChild(myDiv); | |
var im = document.createElement("img"); | |
im.src = "im.gif"; | |
frag.appendChild(im); | |
document.body.appendChild(frag); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment