Created
January 29, 2012 21:56
-
-
Save skylamer/1700894 to your computer and use it in GitHub Desktop.
javascript naturalzz
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
$(document).ready(function()) | |
___ | |
document.addEventListener("DOMContentLoaded", function() {}); | |
/// | |
$("something"); | |
___ | |
document.querySelectorAll("something"); | |
/// | |
$("<tag/>"); | |
___ | |
document.createElement("tag"); | |
/// | |
tag.addClass("klass"); | |
___ | |
tag.classList.add("klass"); | |
/// | |
tag.toggleClass("klass"); | |
___ | |
tag.classList.toggle("klass"); | |
/// | |
$("a").click(function() {}) | |
___ | |
[].forEach.call(document.querySelectorAll("a"), function(el) { | |
el.addEventListener("click", function() { | |
}, false); | |
}); | |
/// | |
$("body").append($("<p/>")); | |
___ | |
document.body.appendChild(document.createElement("p")); | |
/// | |
$("img").filter(":first").attr("alt", "My image"); | |
___ | |
document.querySelector("img").setAttribute("alt", "My image"); | |
/// | |
var parent = $("#about").parent(); | |
___ | |
var parent = document.querySelector("#about").parentNode; | |
/// | |
var clonedElement = $("#about").clone(); | |
___ | |
var clonedElement = document.querySelector("#about").cloneNode(true); | |
/// | |
$("#wrap").empty(); | |
___ | |
var wrap = document.querySelector("#wrap"); | |
while(wrap.firstChild) wrap.removeChild(wrap.firstChild); | |
/// | |
if($("#wrap").is(":empty")) | |
___ | |
if(!document.querySelector("#wrap").hasChildNodes()) | |
/// | |
var nextElement = $("#wrap").next(); | |
___ | |
var nextElement = document.querySelector("#wrap").nextSibling; | |
/// | |
$('#container').find('li'); | |
___ | |
document.querySelectorAll('#container li'); | |
/// | |
$('ul').on('click', 'a', fn); | |
___ | |
document.addEventListener('click', function(e) { | |
if ( e.target.matchesSelector('ul a') ) { | |
} | |
}, false); | |
/// | |
$('.box').css('color', 'red'); | |
___ | |
[].forEach.call( document.querySelectorAll('.box'), function(el) { | |
el.style.color = 'red'; // or add a class | |
}); | |
/// | |
$() | |
___ | |
var $ = function(i) { | |
if(i.search("#")!==-1) return document.querySelector(i); | |
return document.querySelectorAll(i); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment