http://sharedfil.es/js-48hIfQE4XK.html 내용.
맘에 들어서 퍼옴.
포인트는 querySelector 같은게 IE 에서 되면 뭐다러 jQuery selector를 쓰냐
forEach가 먹으면 뭐하러 귀찮게 $.each를 쓰냐.
이게 다 IE 때문이다. 그래서 jQuery 를 쓴다.
맘에 들어서 퍼옴.
포인트는 querySelector 같은게 IE 에서 되면 뭐다러 jQuery selector를 쓰냐
forEach가 먹으면 뭐하러 귀찮게 $.each를 쓰냐.
이게 다 IE 때문이다. 그래서 jQuery 를 쓴다.
| jQuery | JavaScript |
|---|---|
$(document).ready(function() { // code…});
| document.addEventListener("DOMContentLoaded", function() { // code…});
|
var divs = $("div");
| var divs = document.querySelectorAll("div");
|
var newDiv = $("<div/>");
| var newDiv = document.createElement("div");
|
newDiv.addClass("foo");
| newDiv.classList.add("foo");
|
newDiv.toggleClass("foo");
| newDiv.classList.toggle("foo");
|
$("a").click(function() { // code…})
| [].forEach.call(document.querySelectorAll("a"), function(el) { el.addEventListener("click", function() { // code… });});
|
$("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.getElementById("about").parentNode;
|
var clonedElement = $("#about").clone();
| var clonedElement = document.getElementById("about").cloneNode(true);
|
$("#wrap").empty();
| var wrap = document.getElementById("wrap");while(wrap.firstChild) wrap.removeChild(wrap.firstChild);
|
if($("#wrap").is(":empty"))
| if(!document.getElementById("wrap").hasChildNodes())
|
var nextElement = $("#wrap").next();
| var nextElement = document.getElementById("wrap").nextSibling;
|
댓글
댓글 쓰기