250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 백엔드
- effect
- HTML
- php
- IOS
- Animation
- javascript
- iOS 개발자
- css3
- jQuery
- 프론트엔드
- CSS
- hover
- 비전공 개발자
- ipad
- iPhone
- 자바스크립트
- 개발자
- html5
- MAC
- 애니메이션
- SWIFT
- image
- xcode
- react
- front-end
- button
- keyframes
- 풀스택
- 비전공자
Archives
- Today
- Total
비전공자 개발일기
Conditional Statements in jQuery 본문
728x90
SMALL
특정 클래스 존재 유무에 따른 jQuery 실행문 예시
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Conditional Statements in jQuery</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4544051457126963"
crossorigin="anonymous"></script>
<style>
.container {
text-align: center;
width: 200px;
height: 200px;
border: 1px solid;
}
.box0 {
width: 50px;
height: 50px;
background-color: red;
text-align: center;
line-height: 50px;
}
.box1 {
width: 50px;
height: 50px;
background-color: orange;
text-align: center;
line-height: 50px;
}
.box2 {
width: 50px;
height: 50px;
background-color: royalblue;
text-align: center;
line-height: 50px;
}
.box3{
width: 50px;
height: 50px;
background-color: green;
text-align: center;
line-height: 50px;
}
</style>
</head>
<body>
<div class="container">
<div class="box1">BOX1</div>
<div class="box2">BOX2</div>
<div class="box3">BOX3</div>
</div>
</body>
<script>
$(function() {
let code = "<div class=box3>BOX3</div>"
let code2 = "<div class=box0>BOX0</div>"
if(!$("div").hasClass("box3")) {
$(".container").append(code);
} else {
$(".box1").before(code2)
}
});
</script>
</html>
728x90
LIST
'JQuery' 카테고리의 다른 글
Read More & Read Less Button (0) | 2022.05.08 |
---|---|
Dynamic Select Option (0) | 2022.05.04 |
JQuery - input & button Event (0) | 2022.01.05 |
JQuery - sortable (0) | 2021.12.27 |
JQuery 17 - datepicker (0) | 2021.12.24 |