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 ํŒŒ์ผ์— ๋ณต๋ถ™ํ•˜๋ฉด ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค.

๐Ÿ’ซ ๊ธฐ๋ณธ ์‚ฌ์šฉ๋ฒ•

  1. querySelector
<p class="hello">Dozzing</p>

<script>
    //JavaScript
    document.querySelector('.hello').innerHTML = 'World';
    //jQuery
    $('.hello').html('World'); 
</script>
  1. ์Šคํƒ€์ผ ๋ณ€๊ฒฝ
<p class="hello">Dozzing</p>

<script>
    //JavaScript
    document.querySelector('.hello').style.color = 'purple';
    //jQuery
    $('.hello').css('color', 'purple');
</script>
  1. class ํƒˆ๋ถ€์ฐฉ
<p class="hello">์•ˆ๋…•</p>

<script>
  ('.hello').addClass('ํด๋ž˜์Šค๋ช…');('.hello').removeClass('ํด๋ž˜์Šค๋ช…');
  $('.hello').toggleClass('ํด๋ž˜์Šค๋ช…');
</script>
  1. 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>
  1. ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ
<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>
  1. 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>

By Dozzing

๋‹ต๊ธ€ ๋‚จ๊ธฐ๊ธฐ

์ด๋ฉ”์ผ ์ฃผ์†Œ๋Š” ๊ณต๊ฐœ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ํ•„์ˆ˜ ํ•„๋“œ๋Š” *๋กœ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค