Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 |
30 | 31 |
Tags
- 학습일기
- 페이지분석
- TIOBE index
- 학습기록
- shinahyo
- js
- 엘리사이트분석
- 프로그래밍독학
- html
- 퍼스널브랜딩
- php
- 프로그래밍 공부
- 개발학습
- 오늘배운것
- 유튜브학습
- 드림코딩엘리
- 개발공부
- 개발 공부
- 생활코딩html
- 프로그래밍
- til
- 드로우앤드류
- 프로그래밍언어 통계
- 프로그래밍언어
- 사이트구조
- 사이트분석
- 자기계발
- 웹앱만들기
- 생활코딩
- 웹페이지분석
Archives
- Today
- Total
신나yo-TechBlog
Toggle이란? (html, Javascript) 본문
728x90
toggle에 대한 예시
오늘 실행해본 실습으로 예를 들면, night/day버튼을 하나로 통합해서 만드는 것.
night상태의 버튼을 클릭하면, <배경 검정, 글씨 하양, 버튼 내 글자(value) day>로 바뀌고
day상태의 버튼 클릭하면, <배경 하양, 글씨 검정, 버튼 내 글자 night>로 바뀌는 기능을 지정한 html 코드가
바로 아래 예시!
<input id="night_day" type="button" value="night" onclick="
if(document.querySelector('#night_day').value === 'night'){
document.querySelector('body').style.backgroundColor = 'black';
document.querySelector('body').style.color = 'white';
document.querySelector('#night_day').value ='day';
} else {
document.querySelector('body').style.backgroundColor = 'white';
document.querySelector('body').style.color = 'black';
document.querySelector('#night_day').value = 'night';
}
">
토글이란?
클릭이벤트와 선택된 element 사이에 둘 또는 그 이상의 기능을 부여하는 방식이다.
한 번 클릭하면, 첫 번째로 지정된 기능이 작둉하고, 다시 클릭하면, 두 번째 기능이 작동한다.
출처: w3schools jQuery toggle method
jQuery toggle() Method
jQuery toggle() Method ❮ jQuery Effect Methods Example Toggle between hide and show for all
elements: $("button").click(function(){ $("p").toggle(); }); Try it Yourself » Definition and Usage The toggle() method toggles between hide() and show()
www.w3schools.com
728x90
'TIL: theory > Javascript' 카테고리의 다른 글
JS 기본 문법 복습 with PHP (0) | 2021.04.12 |
---|---|
JS가 "동적 언어, 클라이언트 side 언어"인 이유(feat.PHP) (0) | 2021.04.11 |
JS / egoing / web2 JavaScript / 생활코딩(오픈튜토리얼스) (0) | 2021.03.30 |
Comments