- 전체
- HTML
- Web Design (웹디자인)
- XE 응용 개발
- wordpress plugin dev
- Javascript & JavaScript Application
- MEAN Stack : full stack javascript
- angular js & ionic framework
- bootstrap
- WebGL, Three.js and Babylon.js
- restful api design
- mobile web
- node.js 응용
- Cloud Service 응용
- 웹 어셈블리 개발 [WASM, WebAssembly]
- 마이크로서비스, MSA (microservice architecture)
- WebGL / WebGPU
- next.js 개발
- micro frontend (마이크로프론트앤드)
- 전자상거래/쇼핑몰
- 서버 클라우드 (aws, azure, google)
JavaScript [pure javascript] Vanilla JS equivalents of jQuery methods
2020.03.09 09:01
[pure javascript] Vanilla JS equivalents of jQuery methods
Sans jQuery
Events
// jQuery
$(document).ready(function() {
// code
})
// Vanilla
document.addEventListener('DOMContentLoaded', function() {
// code
})
// jQuery
$('a').click(function() {
// code…
})
// Vanilla
[].forEach.call(document.querySelectorAll('a'), function(el) {
el.addEventListener('click', function() {
// code…
})
})
Selectors
// jQuery
var divs = $('div')
// Vanilla
var divs = document.querySelectorAll('div')
// jQuery
var newDiv = $('<div/>')
// Vanilla
var newDiv = document.createElement('div')
Attributes
// jQuery
$('img').filter(':first').attr('alt', 'My image')
// Vanilla
document.querySelector('img').setAttribute('alt', 'My image')
Classes
// jQuery
newDiv.addClass('foo')
// Vanilla
newDiv.classList.add('foo')
// jQuery
newDiv.toggleClass('foo')
// Vanilla
newDiv.classList.toggle('foo')
Manipulation
// jQuery
$('body').append($('<p/>'))
// Vanilla
document.body.appendChild(document.createElement('p'))
// jQuery
var clonedElement = $('#about').clone()
// Vanilla
var clonedElement = document.getElementById('about').cloneNode(true)
// jQuery
$('#wrap').empty()
// Vanilla
var wrap = document.getElementById('wrap')
while(wrap.firstChild) wrap.removeChild(wrap.firstChild)
Transversing
// jQuery
var parent = $('#about').parent()
// Vanilla
var parent = document.getElementById('about').parentNode
// jQuery
if($('#wrap').is(':empty'))
// Vanilla
if(!document.getElementById('wrap').hasChildNodes())
// jQuery
var nextElement = $('#wrap').next()
// Vanilla
var nextElement = document.getElementById('wrap').nextSibling
AJAX
GET
// jQuery
$.get('//example.com', function (data) {
// code
})
// Vanilla
var httpRequest = new XMLHttpRequest()
httpRequest.onreadystatechange = function (data) {
// code
}
httpRequest.open('GET', url)
httpRequest.send()
POST
// jQuery
$.post('//example.com', { username: username }, function (data) {
// code
})
// Vanilla
var httpRequest = new XMLHttpRequest()
httpRequest.onreadystatechange = function (data) {
// code
}
httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
httpRequest.open('POST', url)
httpRequest.send('username=' + encodeURIComponent(username))
JSONP
// jQuery
$.getJSON('//openexchangerates.org/latest.json?callback=?', function (data) {
// code
})
// Vanilla
function success(data) {
// code
}
var scr = document.createElement('script')
scr.src = '//openexchangerates.org/latest.json?callback=formatCurrency'
document.body.appendChild(scr)
More
Here are a few additional references demonstrating vanilla javascript equivalents of jquery methods:
Also, see the two part series showing equivalents for ...
-
[Events, Ajax and Utilities](http://www.sitepoint.com/jquery-vs-raw- javascript-3-events-ajax/)
[출처] https://gist.github.com/joyrexus/7307312
본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
댓글 0
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
|---|---|---|---|---|
| 7 | [전자상거래/쇼핑몰 개발] [카페24쇼핑몰] 품목생성형과 상품연동형 옵션의 차이점이 궁금합니다. | 졸리운_곰 | 2024.07.30 | 385 |
| 6 |
[전자상거래/쇼핑몰 개발] cafe24 MySQL db 외부접속 방법
| 졸리운_곰 | 2024.07.23 | 566 |
| 5 |
[전자상거래/쇼핑몰 개발] 초보 셀러를 위한 쇼피파이(Shopify) 제작 가이드
| 졸리운_곰 | 2024.07.03 | 585 |
| 4 |
[전자상거래/쇼핑몰 개발] [카페24쇼핑몰] [API] Cafe24 - API 호출 예시
| 졸리운_곰 | 2024.06.25 | 413 |
| 3 | [전자상거래/쇼핑몰 개발] [카페24쇼핑몰] 카페24 무료 쇼핑몰 가입 | 졸리운_곰 | 2024.05.20 | 543 |
| 2 | [전자상거래/쇼핑몰 개발] [카페24쇼핑몰] 카페24 쇼핑몰 상세화면 설정 | 졸리운_곰 | 2024.05.20 | 244 |
| 1 |
[전자상거래/쇼핑몰 개발] [카페24쇼핑몰] 상품상세 검색
| 졸리운_곰 | 2024.05.17 | 611 |

