See the Pen
์๋ฐ์คํฌ๋ฆฝํธ ๋ชจ๋ฌ์ฐฝ by dozzs (@dozzs)
on CodePen.
๐ซ jQuery
write less, do more.
HTML ์ ํด๋ผ์ด์ธํธ ์ฌ์ด๋ ์คํฌ๋ฆฝํธ ์ธ์ด๋ฅผ ๋จ์ํํ๋๋ก ์ค๊ณ๋ ๋ธ๋ผ์ฐ์ ํธํ์ฑ์ด ์๋ JavaScript ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ด๋ค. ์กด ๋ ์(John Resig)์ ์ํด 2006๋ ๋ด์ ์ ๋ฐ์บ ํ(Barcamp NYC)์์ ๊ณต์์ ์ผ๋ก ์๊ฐ๋์๋ค.
ํน์ฅ์ ์ ๋ฐ๋ก ๋ฌด์งํ๊ฒ ์ฝ๊ณ ๊ฐํธํ๋ค๋ ์ ์ด๋ค.
๐ซ ์ค์น
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
์ ์ฝ๋๋ฅผ HTML ํ์ผ์ ๋ณต๋ถํ๋ฉด ์ฌ์ฉ ๊ฐ๋ฅํ๋ค.
๐ซ ๊ธฐ๋ณธ ์ฌ์ฉ๋ฒ
- querySelector
<p class="hello">Dozzing</p>
<script>
//JavaScript
document.querySelector('.hello').innerHTML = 'World';
//jQuery
$('.hello').html('World');
</script>
- ์คํ์ผ ๋ณ๊ฒฝ
<p class="hello">Dozzing</p>
<script>
//JavaScript
document.querySelector('.hello').style.color = 'purple';
//jQuery
$('.hello').css('color', 'purple');
</script>
- class ํ๋ถ์ฐฉ
<p class="hello">์๋
</p>
<script>
('.hello').addClass('ํด๋์ค๋ช
');('.hello').removeClass('ํด๋์ค๋ช
');
$('.hello').toggleClass('ํด๋์ค๋ช
');
</script>
- HTML ์ฌ๋ฌ ๊ฐ ๋ฐ๊พธ๊ธฐ
<p class="hello">Dozzing</p>
<p class="hello">Dozzing</p>
<p class="hello">Dozzing</p>
<script>
//JavaScript
document.querySelectorAll('.hello')[0].innerHTML = 'World';
document.querySelectorAll('.hello')[1].innerHTML = 'World';
document.querySelectorAll('.hello')[2].innerHTML = 'World';
//jQuery
$('.hello').html('World');
</script>
- ์ด๋ฒคํธ ๋ฆฌ์ค๋
<p class="hello">Dozzing</p>
<button class="test-btn">๋ฒํผ</button>
<script>
//JavaScript
document.querySelector('.test-btn').addEventListener('click', function () {
document.querySelector('.hello').style.color = 'purple';
});
//jQuery
('.test-btn').on('click', function(){('.hello').css('color', 'purple');
});
</script>
- UI ์ ๋๋ฉ์ด์
<p class="hello">Dozzing</p>
<button class="test-btn">๋ฒํผ</button>
<script>
('.test-btn').on('click', function(){('.hello').fadeOut(); //์์ํ ์ฌ๋ผ์ง๊ฒ
('.hello').fadeIn(); //์์ํ ์๊ธฐ๊ฒ('.hello').hide(); //์ฌ๋ผ์ง๊ฒ
('.hello').show(); //์๊ธฐ๊ฒ('.hello').slideUp(); //์ฌ๋ผ๊ฐ๋ฉด์ ์ฌ๋ผ์ง๊ฒ
$('.hello').slideDown(); //๋ด๋ ค๊ฐ๋ฉด์ ์๊ธฐ๊ฒ
});
</script>