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
- 이클립스 오라클 연동
- 리스트 모달창
- 상속
- 객체협력
- 사용자 데이터그램 프로토콜
- IP
- Java
- 깃 명령어
- oracle 연동
- downcasting
- react
- 모달창 여러개
- order by
- static 예제
- spring annotation
- singleton
- 싱클톤패턴
- SUB Query
- GROUP BY
- Servlet 맵핑
- 다중 모달창
- AOP란?
- static
- 형변환
- 스프링 모달창
- 다운캐스팅
- static메서드
- 오라클 비교연산자
- 추상 메서드
- 템플릿
Archives
- Today
- Total
모든지 기록하자!
DOM ( Document Object Model ) 본문
728x90
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<!--
DOM : Document Object Model
각 tag를 접근하기 위한 object
그 object를 접근하기 위한 함수들
document -> 문서안에 tag에 접근하도록 만들어진 object
getElementById
getElementByClass []
getElementByName []
getElementByTagName []
-->
<!-- childNodes -->
<h3 id="intro">h3 tag id=intro</h3>
<p id="demo">p tag id=demo</p>
<button type="button" onclick="func()">버튼</button>
<script type="text/javascript">
function func() {
// let text = document.getElementById("intro").childNodes[0].nodeValue;
let text = document.getElementById("demo").childNodes[0].nodeValue;
alert(text);
}
</script>
<br><br>
<select id="cars">
<option>Benz</option>
<option>BMW</option>
<option>Volvo</option>
</select>
<button type="button" onclick="cars()">선택 </button>
<script type="text/javascript">
function cars() {
let carName = document.getElementById("cars").childNodes;
// alert(carName.length);
alert(carName[3].text); //childNodes는 무조껀 긁어올수 있다.
}
</script>
<br><br>
<!-- appendChild(뒤) insertChild(앞) -->
<div id="div1">
<p id="p1">첫번째 p태그</p>
<p id="p2">두번째 p태그</p>
</div>
<button type="button" onclick="appendfunc()">뒤에추가</button>
<button type="button" onclick="insertfunc()">앞에추가</button>
<button type="button" onclick="deletefunc()">삭제</button>
<script type="text/javascript">
function appendfunc() {
let ptag = document.createElement('p'); //<p></>
let textNode = document.createTextNode("새로운 p 태그");
//id와 class를 추가
ptag.id = 'newid';
ptag.className = 'newclass';
ptag.appendChild(textNode); //<p id='newid' clas='newclass'>새로운 p태그</p>
let element = document.getElementById('div1');
element.appendChild(ptag);
}
function insertfunc() {
let h3tag = document.createElement('h3');
let textNode = document.createTextNode("h3 태그를 추가");
h3tag.appendChild(textNode); // <h3>h3 태그를 추가</h3>
let element = document.getElementById('div1');
let elementBefore = document.getElementById('p2'); // 이 요소의 앞에
element.insertBefore(h3tag, elementBefore);
}
function deletefunc() {
let element = document.getElementById('div1');
let removeElement = document.getElementById("p2");
element.removeChild(removeElement);
}
</script>
</body>
</html>
728x90
Comments