[Js] HTML Element | ๋จ์์ ๋ณต์ | DOM
- -
๋ชจ๋ ํฌ์คํ ์ ์ธํ๋ฐ [์ํ์ฝ๋ฉ] ์๋ฐ์คํฌ๋ฆฝํธ ๊ฐ์์ ๋ด์ฉ์ ๋ด๊ณ ์์ผ๋ฉฐ
์ถ์ฒ๋ ์๋์ ์ฃผ์๋ก "egoing Lee"๋์ ์๋ฃ์ ๋๋ค.
์์ ์ ์ธ ์๋๊ฐ ์๋ ๊ณต๋ถํ ๊ฒ์ ์ ๋ฆฌํด๋๋ ๋ชฉ์ ์ผ๋ก ํฌ์คํ ํ ๊ฒ์ ๋๋ค.
์น๋ธ๋ผ์ฐ์ Javascript (์๋ฐ์คํฌ๋ฆฝํธ) - ์ธํ๋ฐ
์ํ์ฝ๋ฉ ์๋ฐ์คํฌ๋ฆฝํธ ๊ฐ์ข ์ ๋๋ค. ์น๋ธ๋ผ์ฐ์ ๋ฅผ ์ง์ ์ ์ดํ ์ ์๋ ์๋ฐ์คํฌ๋ฆฝํธ ๋ ํผ๋ฐ์ค๋ฅผ ๊ณต๋ถํด ๋ด ๋๋ค. ์ด๊ธ ์น ๊ฐ๋ฐ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด JavaScript ์จ๋ผ์ธ ๊ฐ์ ์๋ฐ์คํฌ๋ฆฝํธ ๊ฐ์ข
www.inflearn.com
HTMLElement
getElement* ๋ฉ์๋๋ฅผ ํตํด์ ์ํ๋ ๊ฐ์ฒด๋ฅผ ์กฐํํ๋ค๋ฉด ์ด ๊ฐ์ฒด๋ค์ ๋์์ผ๋ก ๊ตฌ์ฒด์ ์ธ ์์ ์ ์ฒ๋ฆฌํด์ผ ํ๋ค.
์ด๋ฅผ ์ํด์๋ ํ๋ํ ๊ฐ์ฒด๊ฐ ๋ฌด์์ธ์ง ์์์ผ ํ๋ค. ๊ทธ๋์ผ ์ ์ ํ ๋ฉ์๋๋ ํ๋กํผํฐ๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
์๋ ์ฝ๋๋ getElement*์ ๋ฆฌํด ๊ฐ์ ๋ณด์ฌ์ค๋ค.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<ul>
<li>HTML</li>
<li>CSS</li>
<li id="active">JavaScript</li>
</ul>
<script>
var li = document.getElementById('active');
console.log(li.constructor.name);
var lis = document.getElementsByTagName('li');
console.log(lis.constructor.name);
</script>
</body>
</html>
์คํ๊ฒฐ๊ณผ
HTMLLIElement
HTMLCollection
์ด๊ฒ์ ํตํด์ ์ ์ ์๋ ๊ฒ์ ์๋์ ๊ฐ๋ค.
-
document.getElementById : ๋ฆฌํด ๋ฐ์ดํฐ ํ์ ์ HTMLLIELement
-
document.getElementsByTagName : ๋ฆฌํด ๋ฐ์ดํฐ ํ์ ์ HTMLCollection
์ฆ ์คํ๊ฒฐ๊ณผ๊ฐ ํ๋์ธ ๊ฒฝ์ฐ HTMLLIELement, ๋ณต์์ธ ๊ฒฝ์ฐ HTMLCollection์ ๋ฆฌํดํ๊ณ ์๋ค.
HTMLELement
์คํ๊ฒฐ๊ณผ๊ฐ ํ๋์ธ ์๋ฆฌ๋จผํธ๋ค์ ์ข ๋ ์ดํด๋ณด์.
<a id="anchor" href="http://opentutorials.org">opentutorials</a>
<ul>
<li>HTML</li>
<li>CSS</li>
<li id="list">JavaScript</li>
</ul>
<input type="button" id="button" value="button" />
<script>
var target = document.getElementById('list');
console.log(target.constructor.name);
var target = document.getElementById('anchor');
console.log(target.constructor.name);
var target = document.getElementById('button');
console.log(target.constructor.name);
</script>
๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ๋ค.
HTMLLIElement
HTMLAnchorElement
HTMLInputElement
์ด๋ฅผ ํตํด์ ์ ์ ์๋ ๊ฒ์ ์๋ฆฌ๋จผํธ์ ์ข ๋ฅ์ ๋ฐ๋ผ์ ๋ฆฌํด๋๋ ๊ฐ์ฒด๊ฐ ์กฐ๊ธ์ฉ ๋ค๋ฅด๋ค๋ ๊ฒ์ด๋ค.
๊ฐ๊ฐ์ ๊ฐ์ฒด์ ์ฐจ์ด์ ์ ์์๋ณด์. ๋งํฌ๋ DOM์ ์คํ์ด๋ค.
HTMLLIElement๋ฅผ ๋ณด์.
interface HTMLLIElement : HTMLElement {
attribute DOMString type;
attribute long value;
};
๋ค์์ HTMLAnchroElement์ด๋ค.
interface HTMLAnchorElement : HTMLElement {
attribute DOMString accessKey;
attribute DOMString charset;
attribute DOMString coords;
attribute DOMString href;
attribute DOMString hreflang;
attribute DOMString name;
attribute DOMString rel;
attribute DOMString rev;
attribute DOMString shape;
attribute long tabIndex;
attribute DOMString target;
attribute DOMString type;
void blur();
void focus();
};
์๋ฆฌ๋จผํธ ๊ฐ์ฒด์ ๋ฐ๋ผ์ ํ๋กํผํฐ๊ฐ ๋ค๋ฅด๋ค๋ ๊ฒ์ ์ ์ ์๋ค.ํ์ง๋ง ๋ชจ๋ ์๋ฆฌ๋จผํธ๋ค์ HTMLElement๋ฅผ ์์ ๋ฐ๊ณ ์๋ค.
interface HTMLLIElement : HTMLElement {
interface HTMLAnchorElement : HTMLElement {
HTMLElement๋ ์๋์ ๊ฐ๋ค.
interface HTMLElement : Element {
attribute DOMString id;
attribute DOMString title;
attribute DOMString lang;
attribute DOMString dir;
attribute DOMString className;
};
DOM Tree
๋ชจ๋ ์๋ฆฌ๋จผํธ๋ HTMLElement์ ์์์ด๋ค. ๋ฐ๋ผ์ HTMLElement์ ํ๋กํผํฐ๋ฅผ ๋๊ฐ์ด ๊ฐ์ง๊ณ ์๋ค. ๋์์ ์๋ฆฌ๋จผํธ์ ์ฑ๊ฒฉ์ ๋ฐ๋ผ์ ์์ ๋ง์ ํ๋กํผํฐ๋ฅผ ๊ฐ์ง๊ณ ์๋๋ฐ ์ด๊ฒ์ ์๋ฆฌ๋จผํธ์ ์ฑ๊ฒฉ์ ๋ฐ๋ผ์ ๋ฌ๋ผ์ง๋ค.
HTMLElement๋ Element์ ์์์ด๊ณ Element๋ Node์ ์์์ด๋ค.
Node๋ Object์ ์์์ด๋ค. ์ด๋ฌํ ๊ด๊ณ๋ฅผ DOM Tree๋ผ๊ณ ํ๋ค. ์ด ๊ด๊ณ๋ฅผ ๊ทธ๋ฆผ์ผ๋ก ๋ํ๋ด๋ฉด ์๋์ ๊ฐ๋ค.
์ด๋ฌํ ๊ด๊ณ๋ฅผ ์ดํดํ์ง ๋ชปํ๋ฉด ํ์ํ API๋ฅผ ์ฐพ์๋ด๋ ๊ฒ์ด ์ด๋ ต๊ฑฐ๋ ๋ชน์ ํผ๋์ค๋ฌ์ธ ๊ฒ์ด๋ค.
๋คํ์ธ ๊ฒ์ jQuery์ ๊ฐ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ด์ฉํ๋ค๋ฉด ์ด๋ฌํ ๊ด๊ณ๋ฅผ ๋ชฐ๋ผ๋ ๋๋ค. ํน์ ์ดํด๊ฐ ์๋๋ค๊ณ ๋๋ฌด ์์ฌํ์ง ๋ง์.
'Languages > Java Script' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Js] jQuery ๊ฐ์ฒด | map() | jQuery API (0) | 2021.02.08 |
---|---|
[Js] HTML Collection | DOM | javascript (0) | 2021.02.08 |
[Js] jQuery ์ ์ด ๋์์ฐพ๊ธฐ | jQuery | javascript (0) | 2021.02.08 |
[Js] jQuery | ๋ผ์ด๋ธ๋ฌ๋ฆฌ | DOM base jQuery (0) | 2021.02.07 |
์์คํ ๊ณต๊ฐ ๊ฐ์ฌํฉ๋๋ค