jQuery란?
자바스크립트를 쉽게 사용하게 해주는 라이브러리
간결한 문법, 편리한 api, 크로스 브라우징의 장점이 있다.
사용방법
code.jquery.com에서 코드 복사해오기
<script
src="https://code.jquery.com/jquery-3.5.1.js"
integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc="
crossorigin="anonymous"></script>
//jquery를 이용해 값 가져오기
$('#content').val()
이벤트
<button id="click" onclick="hello();">클릭</button>
function hello() {
console.log('hello');
}
// jQuery 문법으로 바꾸기
<button id="click">클릭</button>
function hello() {
console.log('hello');
}
$('#click').click(hello);
익명함수
함수를 정의하지 않고 바로 사용하기
$('#click').click(function(){
console.log('hello');
});