JavaScript
[JavaScript] jQuery
댕주
2024. 11. 17. 01:22
jQuery는 JavaScript를 간단하고 효율적으로 작성할 수 있게 도와주는 JavaScript 라이브러리이다.
특징
- 간결한 코드: 복잡한 JavaScript 코드를 몇 줄로 대체 가능
- DOM 조작: HTML 요소를 쉽게 선택하고 조작
- 이벤트 처리: 브라우저 간 차이 없이 클릭, 입력 등의 이벤트를 처리
- AJAX: 비동기 요청을 간편하게 처리
- 크로스브라우징 지원: 다양한 브라우저에서 동일하게 동작
기본 문법
$() 로 요소 선택
$('#id') // id
$('.class') // class
$('tag') // 태그
DOM 조작
$('#example').text('새로운 텍스트'); // 텍스트 변경
$('.example').css('color', 'red'); // CSS 스타일 변경
이벤트 처리
$('#button').on('click', function() {
alert('버튼 클릭');
});
jQuery와 네이티브 JavaScript 비교
HTML 요소의 텍스트 변경
// JavaScript
document.getElementById('example').innerText = '새 텍스트 입력';
// jQuery
$('#example').text('새 텍스트 입력');
설치 방법
- CDN 이용하기
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
- 로컬 설치하기
공식 사이트에서 다운로드 https://jquery.com/
프로젝트에 jquery.min.js 파일 추가
jQuery
What is jQuery? jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
jquery.com