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 | 29 | 30 | 31 |
Tags
- javascrpit 기초
- react forwardRef
- spring builder
- springbatch
- javascript 기초
- SpringBatch 스키마
- 코드 중복제거
- Spring CORS
- 텍스트가 많은 경우
- Spring JPA
- Spring Controller return
- springbatch chunk
- editor Quill
- react link
- Docker Windows 설치
- react jsx if
- JPA Insert
- react
- react Quill
- Spring Entity
- JPA Update\
- react react-router-dom v6
- step 테이블
- javascript 함수
- react quill custom
- Spring DTO
- spring security
- Javascript
- spring
- react Page
Archives
- Today
- Total
천천히 알아보는 코딩공부
HTML in Javascript 본문
HTML in Javascript
- Document
- Searching For Element
document.GetelementById("title") // id가 title인걸 가져옴
console.log(title.id);
console.log(title.className);
title.innerText= "Hi"; // 해당 id 내용 추가
document.GetelementClassName("something"); class가 something인걸 가져옴
document.querySelection(".hello h1");
// css방식으로 검색 class가 hello 안에 h1 찾기 (첫 번째로 해당 되는 것만 가져옴)
document.querySelection("#hello from"); // id인 hello 그 밑의 from id 가져옴
document.querySelectionAll(".hello h1");
// css방식으로 검색 hello 클래스 안에 h1 찾기 (해당 되는 전부 가져옴 Array)
const title = document.querySelection(".div.hello:first-child h1");
//클래스 hello를 가진 div 내부의 firstchild 인 h1 가져오기
title.style.color = "blue"; // 글씨색
- Event
기본 document Element
https://developer.mozilla.org/ko/docs/Web/API/element
Element - Web API | MDN
Element는 Document 안의 모든 객체가 상속하는 제일 범용적인 기반 클래스로 공통 메서드와 속성만 가지고 있으며, 특정 요소를 더 상세하게 표현하는 클래스가 Element를 상속합니다. 예를 들어 HTMLEl
developer.mozilla.org
console.dir("title") // console에서 title 이벤트 찾아내기
const title = document.querySelection(".div.hello:first-child h1");
//클래스 hello를 가진 div 내부의 firstchild 인 h1 가져오기
function handleTitleClick() {
console.log("clicked!");
}
title.addEventListener("click", handleTitleClick);
// 클릭시 handleTitleClick function 실행
function handleMouseEnter()
{
console.log("here!!");
}
title.addEventListener("mouseenter", handleMouseEnter);
// 해당 칸에 마우스 갖다두면 function 실행
function handleMouseLeave()
{
console.log("Leave");
}
title.addEventListener("mouseleave", handleMouseLeave);
// 해당 칸에 마우스 갖다두면 function 실행
title.onclick = handleTitleClick;
title.onmuseenter = handleMouseEnter;
// 이런 방법으로도 이벤트를 호출 할수 있다
Event 조건
const h1 = document.querySelection("div.hello:first-child h1");
//클래스 hello를 가진 div 내부의 firstchild 인 h1 가져오기
function handleTitleClick() {
const currentColor = h1.style.color;
let newColor;
if(currentColor === "blue")
{
newColor = "tomato"
}
else
{
newColor = blue
}
h1.style.color = newColor
}
h1.addEventListener("click", handleTitleClick)
'JavaScript > 기초' 카테고리의 다른 글
javascript 기본 타입, 참조 타입(객체 타입) (0) | 2022.04.19 |
---|---|
javascript 태그 추가 (0) | 2022.03.31 |
JavaScript 기초 정리 2 (0) | 2022.03.29 |
CSS in JavaScript (0) | 2022.03.20 |
JavaScript 기초 정리 (0) | 2022.03.16 |
Comments