(HTML ﺮﺻﺎﻨﻋ) ﺎﻫ ﻩﺮﮔ ﻑﺬﺣ ﻭ ﻥﺩﺮﮐ ﻪﻓﺎﺿﺍ
.ﺪﯿﻨﮐ ﺩﺎﺠﯾﺍ ﺍﺭ (ﺮﺼﻨﻋ ﻩﺮﮔ) ﺮﺼﻨﻋ ﺪﯾﺎﺑ ﺍﺪﺘﺑﺍ ،HTML DOM ﻪﺑ ﺪﯾﺪﺟ ﺮﺼﻨﻋ ﮏﯾ ﻥﺩﻭﺰﻓﺍ ﯼﺍﺮﺑ
<div id="div1">
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>
<script>
const para = document.createElement("p");
const node = document.createTextNode("This is new.");
para.appendChild(node);
const element = document.getElementById("div1");
element.appendChild(para);
</script>
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript HTML DOM</h2>
<p>Add a new HTML Element.</p>
<div id="div1">
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>
<script>
const para = document.createElement("p");
const node = document.createTextNode("This is new.");
para.appendChild(node);
const element = document.getElementById("div1");
element.appendChild(para);
</script>
</body>
</html>
:ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﺪﯾﺪﺟ <p>
ﺮﺼﻨﻋ ﮏﯾ ﺪﮐ ﻦﯾﺍ
const para = document.createElement("p");
:ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﯽﻨﺘﻣ ﻩﺮﮔ ﮏﯾ ﺪﮐ ﻦﯾﺍ .ﺪﯿﻨﮐ ﺩﺎﺠﯾﺍ ﻦﺘﻣ ﻩﺮﮔ ﮏﯾ ﺪﯾﺎﺑ ﺍﺪﺘﺑﺍ ،<p>
ﺮﺼﻨﻋ ﻪﺑ ﺍﺭ ﻦﺘﻣ ﻩﺮﮔ ﺪﯾﺎﺑ ﺲﭙﺳ
para.appendChild(node);
.ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﺩﻮﺟﻮﻣ ﺮﺼﻨﻋ ﮏﯾ ﻪﺑ ﺍﺭ ﺪﯾﺪﺟ ﺮﺼﻨﻋ ﺪﯾﺎﺑ ﺖﯾﺎﻬﻧ ﺭﺩ
:ﺪﻨﮐ ﯽﻣ ﺍﺪﯿﭘ ﺍﺭ ﺩﻮﺟﻮﻣ ﺮﺼﻨﻋ ﮏﯾ ﺪﮐ ﻦﯾﺍ
const element = document.getElementById("div1");
:ﺪﻨﮐ ﯽﻣ ﻪﻓﺎﺿﺍ ﺩﻮﺟﻮﻣ ﺮﺼﻨﻋ ﻪﺑ ﺍﺭ ﺪﯾﺪﺟ ﺮﺼﻨﻋ ﺪﮐ ﻦﯾﺍ
element.appendChild(para);
ﺩﺮﮐ ﻪﻓﺎﺿﺍ ﻥﺍﻮﻨﻋ ﻪﺑ ﺍﺭ ﺪﯾﺪﺟ ﺮﺼﻨﻋ ،ﯽﻠﺒﻗ ﻝﺎﺜﻣ ﺭﺩ appendChild()
:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ insertBefore()
ﺵﻭﺭ ﺯﺍ ﺪﯿﻧﺍﻮﺗﯽﻣ ﺪﯿ
<div id="div1">
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>
<script>
const para = document.createElement("p");
const node = document.createTextNode("This is new.");
para.appendChild(node);
const element = document.getElementById("div1");
const child = document.getElementById("p1");
element.insertBefore(para, child);
</script>
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript HTML DOM</h2>
<p>Add a new HTML Element.</p>
<div id="div1">
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>
<script>
const para = document.createElement("p");
const node = document.createTextNode("This is new.");
para.appendChild(node);
const element = document.getElementById("div1");
const child = document.getElementById("p1");
element.insertBefore(para,child);
</script>
</body>
</html>
.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ remove()
ﺯﺍ ،HTML ﺮﺼﻨﻋ ﮏﯾ ﻑﺬﺣ ﯼﺍﺮﺑ
<div>
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>
<script>
const elmnt = document.getElementById("p1");
elmnt.remove();
</script>
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript HTML DOM</h2>
<h3>Remove an HTML Element.</h3>
<div>
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>
<button onclick="myFunction()">Remove Element</button>
<script>
function myFunction() {
document.getElementById("p1").remove();
}
</script>
</body>
</html>
ﺭﺩ <p>
ﻭﺩ) ﺖﺳﺍ ﺪﻧﺯﺮﻓ ﻩﺮﮔ ﻭﺩ ﺎﺑ remove()
ﺵﻭﺭ
ﺪﯾﺎﺑ ،ﺪﻨﻨﮐ ﯽﻤﻧ ﯽﻧﺎﺒﯿﺘﺸﭘ remove()
ﺵﻭﺭ ﺯﺍ ﻪﮐ ﯽﯾﺎﻫﺮﮔﺭﻭﺮ
<div id="div1">
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>
<script>
const parent = document.getElementById("div1");
const child = document.getElementById("p1");
parent.removeChild(child);
</script>
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript HTML DOM</h2>
<p>Remove Child Element</p>
<div id="div1">
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>
<script>
const parent = document.getElementById("div1");
const child = document.getElementById("p1");
parent.removeChild(child);
</script>
</body>
</html>
<p>
ﻭﺩ) ﺖﺳﺍ ﺪﻧﺯﺮﻓ ﻩﺮﮔ ﻭﺩ ﺎﺑ id="div1"
ﺎﺑ ﺍﺭ ﺮﺼﻨﻋ
const parent = document.getElementById("div1");
:ﺪﯿﻨﮐ ﺍﺪﯿﭘ id="p1"
ﺎﺑ ﺍﺭ <
const child = document.getElementById("p1");
:ﺪﯿﻨﮐ ﺍﺪﺟ ﻦﯾﺪﻟﺍﻭ ﺯﺍ ﺍﺭ ﮎﺩﻮﮐ
parent.removeChild(child);
ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻥﺁ ﺯﺍ ﻭ ﺪﯿﻨﮐ ﺍﺪﯿﭘ ﺪﯿﻨﮐ ﻑﺬﺣ ﺪﯿﻫﺍﻮﺧ ﯽﻣ ﻪﮐ ﺍﺭ ﯼﺪﻧﺯﺮﻓ :ﺩﺭﺍﺩ ﺩﻮﺟﻭ ﻝﻮﻤﻌﻣ ﻞﺣ ﻩﺍ
const child = document.getElementById("p1");
child.parentNode.removeChild(child);
:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ replaceChild()
ﺵﻭﺭ ﺯﺍ ،HTML DOM ﺭﺩ ﺮﺼﻨ
<div id="div1">
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>
<script>
const para = document.createElement("p");
const node = document.createTextNode("This is new.");
para.appendChild(node);
const parent = document.getElementById("div1");
const child = document.getElementById("p1");
parent.replaceChild(para, child);
</script>
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript HTML DOM</h2>
<h3>Replace an HTML Element.</h3>
<div id="div1">
<p id="p1">This is a paragraph.</p>
<p id="p2">This is a paragraph.</p>
</div>
<script>
const parent = document.getElementById("div1");
const child = document.getElementById("p1");
const para = document.createElement("p");
const node = document.createTextNode("This is new.");
para.appendChild(node);
parent.replaceChild(para,child);
</script>
</body>
</html>