Baseline Widely available
Document.getElementById()
ë©ìëë 주ì´ì§ 문ìì´ê³¼ ì¼ì¹íë id
ìì±ì ê°ì§ ìì를 ì°¾ê³ , ì´ë¥¼ ëíë´ë Element
ê°ì²´ë¥¼ ë°íí©ëë¤. IDë 문ì ë´ìì ì ì¼í´ì¼ í기 ë문ì í¹ì ìì를 ë¹ ë¥´ê² ì°¾ì ë ì ì©í©ëë¤.
IDê° ìë ììì ì ê·¼íë ¤ë©´ Document.querySelector()
를 ì¬ì©íì¸ì. 모ë ì íì를 ì¬ì©í ì ììµëë¤.
document.getElementById(id);
매ê°ë³ì
id
ì°¾ì¼ë ¤ë ìì ID. IDë ëì문ì를 구ë¶íë 문ìì´ë¡, 문ì ë´ìì ì ì¼í´ì¼ í©ëë¤. ì¦, íëì ê°ì íëì ììë§ ì¬ì©í ì ììµëë¤.
주ì´ì§ IDì ì¼ì¹íë DOM ìì를 ëíë´ë Element
ê°ì²´. 문ì ë´ì 주ì´ì§ IDê° ìì¼ë©´ null
.
<html>
<head>
<title>getElementById ìì </title>
</head>
<body>
<p id="para">ì´ë¤ ê¸</p>
<button onclick="changeColor('blue');">blue</button>
<button onclick="changeColor('red');">red</button>
</body>
</html>
JavaScript
function changeColor(newColor) {
var elem = document.getElementById("para");
elem.style.color = newColor;
}
ê²°ê³¼ ì©ë²
ë©ìë ì´ë¦ ì¤ "Id"
ì ëì문ìê° ì íí´ì¼ í©ëë¤. getElementByID()
ê° ìì°ì¤ë¬ì ë³´ì¼ì§ë¼ë ì í¨íì§ ìì ì´ë¦ì´ê¸°ì ì¬ì©í ì ììµëë¤.
Document.querySelector()
ë Document.querySelectorAll()
ê³¼ë ë¬ë¦¬ getElementById()
ë ì ì document
ê°ì²´ì ë©ìëë¡ë§ ì¬ì©í ì ìê³ , DOMì ë¤ë¥¸ ê°ì²´ë ë©ìëë¡ ê°ì§ê³ ìì§ ììµëë¤. ID ê°ì 문ì ì ì²´ìì ì ì¼í´ì¼ íë©° "êµì§ì "ì¸ ë²ì ì ì¸ ì´ì ê° ì기 ë문ì
ëë¤.
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>Document</title>
</head>
<body>
<div id="parent-id">
<p>hello word1</p>
<p id="test1">hello word2</p>
<p>hello word3</p>
<p>hello word4</p>
</div>
<script>
var parentDOM = document.getElementById("parent-id");
var test1 = parentDOM.getElementById("test1");
//throw error
//Uncaught TypeError: parentDOM.getElementById is not a function
</script>
</body>
</html>
id
ì ë§ë ììê° ìì ë getElementById()
ë null
ì ë°íí©ëë¤. 매ê°ë³ì id
ê° ëì문ì를 구ë¶íë¤ë ì ì 기ìµíì¸ì. document.getElementById("Main")
ë <div id="main">
ëì null
ì ë°ííëë° "M"ê³¼ "m"ì 구ë¶í기 ë문ì
ëë¤.
문ìì ìë ììë getElementById()
ê° íìíì§ ììµëë¤. ìì를 ëì ì¼ë¡ ìì±í´ì ID를 ë¶ì¬íëë¼ë, Node.insertBefore()
ë ë¹ì·í ë©ìëë¡ ë¬¸ì í¸ë¦¬ì ì½ì
í´ì¼ getElementById()
ë¡ ì ê·¼í ì ììµëë¤.
var element = document.createElement("div");
element.id = "testqq";
var el = document.getElementById("testqq"); // elì´ null!
HTMLì´ ìë 문ì. DOM 구íì²´ë ììì ì´ë¤ ìì±ì´ IDì¸ì§ ìê³ ìì´ì¼ í©ëë¤. 문ìì DTDê° ì ìíê³ ìì§ ìì¼ë©´, ìì±ëª
ì´ "id"ë¼ê³ í´ë ID ì íì¸ê±´ ìëëë¤. XHTML, XUL ë± ì주 ì°ì´ë 문ìì ê²½ì° id
ìì±ì ID ì íì¼ë¡ ì ìíê³ ììµëë¤. ID ì íì ìì±ì´ ì´ë¤ ê²ì¸ì§ 모르ë ë¤ë¥¸ 구íì ê²½ì° null
ì ë°íí©ëë¤.
Document
ë 문ì ìì ììì ì ê·¼í ì ìë ë¤ë¥¸ ë©ìëì ìì±ì¼ë¡ì 참조를 ê°ì§ê³ ììµëë¤.Document.querySelector()
를 ì¬ì©íë©´ 'div.myclass'
ì²ë¼ ì íìë¡ ìì를 íìí ì ììµëë¤.getElementById()
ê° (Ajax í¸ì¶ ë±ì¼ë¡ ë°ì) XML 문ììì "xml:id" ìì± ê°ì ì¬ì©í ì ìëë¡ ëì주ë ë©ìë를 ê°ì§ê³ ììµëë¤.RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4