dom到meotheyoreo§a§to| at ||||||消息|°至|°至|°至| |。 §A| AT | at |°at | post | to | to | a ||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||¶à§a| to | to | || | | | | | | | |
dom -dom -à °°¾°°à §§—® htmlCollection‾€¥ 。 à……nodeList - €€¾—¥ htmlcollectionà -nodeListà°°®®¾¾ -¨ ‾基§ 。 €¥à¾——€²à§à§à§à ðµ
à à§à§¿ /p>
htmlCollection <强> nodelist à ¾类似阵列的阵列!
htmlCollection
getElementsByClassName()à -à àj® °§ ®°¾¾——® ! à§à °à§à
à书籍清单ৠ¦à¦®à¦¾à¦¦à§à¦°à¦à§ পà§à¦°à¦¤à§à¦¯à§à¦à¦à¦ ¾列表项目访问‰�I°§à§à§à§à§ > getElementsbytybytagname()à§à§ - ¦¿ দà§à¦à¦¬à§?ð¤
index.html
<ul>
<li>Bangla</li>
<li>English</li>
<li>Biology</li>
<li>Physics</li>
</ul>
list.js
const list = document.getElementsByTagName("li");
console.log(list);
Output
//HTMLCollection(4) [li, li, li, li]
à ¦¤à§ পারলাম HTMLCollection ঠশà§à¦§à§ HTML elements à¦à§ à§商店 �°à§°°à§à getElementsbythame() �°à §§——¾ �(文本)à �—¾¾¥¶ ¾à§dom元素实际元素 à¦à§à¦¥à¦¾à¦ à¦à¦à¦à¦¿ element DOM ঠlocated à¦à¦à§ সà§à¦ ‾
nodelist dom-domà§à节点
à
1)元素节点 htmlCollection ৗ§ 不同类型的节点
2)文本节点
3)属性节点
4)评论节点
à§à§à „
index.html
<div id="box">
I'm Text Node
<div>I'm Element Node 1</div>
<div>I'm Element Node 2</div>
</div>
text.js
const box = document.getElementById("box");
console.log(box.childNodes);
Output
// NodeList(5) [text, div, text, div, text]
à °°°«à最后一রা দà§à¦à¦¤à§ পারà¦à¦¿, NodeList tag à¦à§à¦²à§à¦ °氨基à§存储
nodelistà主要信息(元素节点)à ¾——见°¾很容易易于不同类型的节点€¾°¬ à°¾¾¾¾—— ! â€à§à¥¶
à ‾ptag - 文字â€à§à¥¶文字à§à§à§à§à颜色¾-..k./。 িà¦à¦¾à¦¬à§ access à¦à¦°à¦¬??
htmlCollection htmlCollection ¾ -à ‿¾ - nodeList ¾? à§à§ -nodeList - n?¿歌à§color的à节点存储
index.html
<div id="container">
<p>First paragraph</p>
Some text between paragraphs.
<p>Second paragraph</p>
</div>
text.js
// Get the container element
var container = document.getElementById("container");
// Get a NodeList containing all child nodes of the container
var nodes = container.childNodes;
// Loop through the NodeList
nodes.forEach(function (node) {
// Check if the node is a text node
if (node.nodeType === Node.TEXT_NODE) {
// Change the text color of text nodes
node.parentNode.style.color = "red";
}
});
à ¾¾¾¾ à§复合物¾!
querySelectorall()àrym> °°°§—®的
const list = document.querySelectorAll("li");
console.log(list);
output
//NodeList(4) [li, li, li, li]
à ‾基¾ 。 ! nodeList - ¶ ÖTHIMAS§
差异 - nodeList - °°相似性 -
১)htmlCollection ¾°°
)htmlCollectionà! €¨¾
à
- ¶à§drig- à �— ® /¾ ¾ -
১)foreach
)条目
৩)键
৪)值
à|:|® à§à|¥à|€à§²à§htmlCollectionà|à|à|à|ªà|ª
- à ()à ¾°£ ®°¾¾htmlCollectionâ最新更新 - ¾ querySelectorall()àr getelementsByname() ° > querySelectorall()àr getElementsByname() ¥¶
htmlCollection
const boxWrapper = document.getElementById("box-wrapper");
const boxes = boxWrapper.getElementsByClassName("box");
console.log(boxes.length); // 4
const div = document.createElement("div");
div.classList.add("box");
div.innerHTML = "box 5";
boxWrapper.appendChild(div);
console.log(boxes.length); // 5
nodelist
const boxes = document.querySelectorAll(".box");
console.log(boxes.length); // 4
const div = document.createElement("div");
div.setAttribute("class", "box");
div.innerHTML = "box 5";
boxWrapper.appendChild(div);
console.log(boxes.length); // 4
- 最后,孩子们à§htmlcollectionà ! ৾ €à§所有类型的节点访问��°°
index.html
<div id="container">
<p>First paragraph</p>
Some text between paragraphs.
<p>Second paragraph</p>
</div>
text.js
var container = document.getElementById('container');
var children = container.children;
// Only includes <p> elements
var childNodes = container.childNodes;
// Includes <p>, text, and text nodes
htmlCollection র ঠà¦à¦¿à¦à§ benefits à¦à¦à§ তাঠà¦à¦à¦¨ HTMLCollection à¦¬à §§ €¹ ¦à¦ªà¦°à¥¤
à ৠ-
১)htmlCollection - °nodeList - 所有类型的节点存储
à§) getElementsByClassName()àm à!€¾—¦ >ৠstatic à