jQuery 정리

·2023년 6월 1일

1. jQuery 사용

jQuery를 사용하기 전, 라이브러리가 필요하다. 직접 공식 홈페이지에 가서 파일을 다운받아 함께 배포하여도 되지만, 권장사항은 CDN 방식이다.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>



2. jQuery 기초 사용 예시

$ = jQuery
$() = jQuery Selector
jQuery function Selector
$(document).ready(function(){
	$('#btn').click(function(){
		$(this).hide();
	});
});



3. API 문서 사이트와 Selector

API 사이트에서 예제를 보고 활용할 수 있으면 된다.
$('body > *').css("color","gold");	//자식 선택자
$('div > *').css("color","red");
$('input[type=text]').css('color','green');



3.1 jQuery 대표 함수(삼총사)

val(), text(), html()

val() => 값 read
text() => 태그 내 텍스트 read
html() => 태그까지 read

괄호 안에 값을 넣게될 경우, read가 아닌 write가 된다.

[주의] 같은 이름의 요소가 여러 개인 상태에서 이름으로 요소를 read하려 할 경우,
      가장 첫번째 요소만 read한다.
profile
이것저것 공부하기

0개의 댓글