jQuery Tutorial
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
www.w3schools.com
- HTML/DOM manipulation
- CSS manipulation
- HTML event methods
- Effects and animations
- AJAX (비동기 처리)
- Utilities
기본 사용 설정: CDN 불러온 후 script 태그 안에 코드 작성
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
// jQuery 내용 작성
});
</script>
// 혹은 이렇게
<script type="text/javascript">
$(function () {
// jQuery 내용 작성
});
</script>
CSS 설정: .css() 함수 사용
색상 변경
// 전체 색상 변경
$("*").css("color", "red");
폰트 변경
// li태그만 폰트 변경
$("li").css("font-family", "궁서체");
// jQuery: font-family, fontFamily 모두 사용 가능
여러 속성 한 번에: 메소드 체인
$("h3, h4")
.css("border", "solid red 5px")
.css("color", "white")
.css("background-color", "orange");
$("h3").css({
border: "solid red 5px",
color: "skyblue",
backgroundColor: "orange",
});
선택자: 태그, id, 클래스 모두 사용 가능
$("#tag").css("textDecoration", "underline");
$(".div").css({
border: "blue double 3px",
});
필터 사용한 선택자
$("div ol li:eq(0)").css("color", "red"); // equal
$("div ol li:lt(2)").css("color", "blue"); // 더 작은
$("div ol li:gt(2)").css("color", "orange"); // 더 큰
$("div ol li:odd").css("color", "yellow"); // 홀수 인덱스
$("div ol li:even").css("color", "white"); // 짝수 인덱스
$("div ol li:not(:first)").css("color", "white"); // 반대: 처음이 아닌 것
하나만
$("div>span").css({
backgroundColor: "yellow",
});
모든 하위
$("div span").css({
backgroundColor: "yellow",
});
속성 가진 것 모두
// type 속성을 가진 것 모두 (checkbox의 테두리는 border에 해당하지 않음)
$("[type]").css("border", "1px blue solid");
특정 속성 가진 것
// name이 name인 것에만
$("[name=name]").css({
color: "red",
backgroundColor: "pink",
border: "dotted 3px blue",
});
'TIL > FrontEnd' 카테고리의 다른 글
[FE] WebStorage 기초 (0) | 2023.04.18 |
---|---|
[JavaScript] addEventListener 사용 함수 parameter 전달 (0) | 2023.04.16 |
[Svelte] SvelteKit으로 웹사이트 만들기 1️⃣ 프로젝트 시작 (0) | 2023.04.01 |
[React-TypeScript] .env 변수 타입 설정하기 (0) | 2022.11.09 |
[React] 헤더에 뒤로가기 버튼 만들기 (1) | 2022.09.20 |