ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ DOM ﺮﺻﺎﻨﻋ


فهرست مطالب

    نمایش فهرست مطالب


ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﯽﺳﺮﺘﺳﺩ ﺎﻬﻧﺁ ﻪﺑ ﻭ ﻩﺩﺮﮐ ﺍﺪﯿﭘ ﺍﺭ HTML ﺮﺻﺎﻨﻋ ﻪﻧﻮﮕﭼ ﻪﮐ ﺩﺯﻮﻣﺁ ﯽﻣ ﺎﻤﺷ ﻪﺑ ﻪﺤﻔﺻ ﻦﯾ


HTML ﺮﺻﺎﻨﻋ ﻦﺘﻓﺎﯾ

.ﺪﯿﻨﮐ ﯼﺭﺎﮑﺘﺳﺩ ﺍﺭ HTML ﺮﺻﺎﻨﻋ ﺪﯿﻫﺍﻮﺧ ﯽﻣ ،ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺎﺑ ،ﺐﻠﻏﺍ

:ﺩﺭﺍﺩ ﺩﻮﺟﻭ ﺭﺎﮐ ﻦﯾﺍ ﯼﺍﺮﺑ ﯽﻔﻠﺘﺨﻣ ﯼﺎﻫ ﻩﺍﺭ .ﺪﯿﻨﮐ ﺍﺪﯿﭘ ﺍﺭ ﺮﺻﺎﻨﻋ ﺪﯾﺎﺑ ﺍﺪﺘﺑﺍ ،ﺭﺎﮐ ﻦﯾﺍ ﻡﺎﺠﻧﺍ

  • ﻪﺳﺎﻨﺷ ﺎﺑ HTML ﺮﺻﺎﻨﻋ ﻦﺘﻓﺎﯾ

  • ﮓﺗ ﻡﺎﻧ ﺎﺑ HTML ﺮﺻﺎﻨﻋ ﻦﺘﻓﺎﯾ

  • ﺱﻼﮐ ﻡﺎﻧ ﺱﺎﺳﺍ ﺮﺑ HTML ﺮﺻﺎﻨﻋ ﻦﺘﻓﺎﯾ

  • CSS ﯼﺎﻫﺮﮕﺑﺎﺨﺘﻧﺍ ﻂﺳﻮﺗ HTML ﺮﺻﺎﻨﻋ ﻦﺘﻓﺎﯾ

  • HTML ءﺎﯿﺷﺍ ﯼﺎﻫ ﻪﻋﻮﻤﺠﻣ ﻂﺳﻮﺗ HTML ﺮﺻﺎﻨﻋ ﻦﺘﻓﺎﯾ


ﻪﺳﺎﻨﺷ ﺎﺑ HTML ﺮﺼﻨﻋ ﻦﺘﻓﺎﯾ

.ﺖﺳﺍ ﺮﺼﻨﻋ ﻪﺳﺎﻨﺷ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ،DOM ﺭﺩ HTML ﺮﺼﻨﻋ ﮏﯾ ﻦﺘﻓﺎﯾ ﯼﺍﺮﺑ ﻩﺍﺭ ﻦﯾﺮﺗ ﻩﺩﺎﺳ

:ﺪﻨﮐ ﯽﻣ ﺍﺪﯿﭘ id="intro" ﺎﺑ ﺍﺭ ﺮﺼﻨﻋ ﻝﺎﺜﻣ ﻦﯾﺍ

ﻝﺎﺜﻣ

const element = document.getElementById("intro");

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript HTML DOM</h2>

<p id="intro">Finding HTML Elements by Id</p>
<p>This example demonstrates the <b>getElementsById</b> method.</p>

<p id="demo"></p>

<script>
const element = document.getElementById("intro");

document.getElementById("demo").innerHTML = 
"The text from the intro paragraph is: " + element.innerHTML;

</script>

</body>
</html>

.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ (ﺮﺼﻨﻋ ﺭﺩ) ﯽﺷ ﮏﯾ ﻥﺍﻮﻨﻋ ﻪﺑ ﺍﺭ ﺮﺼﻨﻋ ﺪﺘﻣ ،ﺩﻮﺷ ﺍﺪﯿﭘ ﺮﺼﻨﻋ ﺮﮔﺍ

.ﺩﻮﺑ ﺪﻫﺍﻮﺧ null ﯼﻭﺎﺣ ﺮﺼﻨﻋ ،ﺪﺸﻧ ﺍﺪﯿﭘ ﺮﺼﻨﻋ ﺮﮔﺍ


ﮓﺗ ﻡﺎﻧ ﺱﺎﺳﺍ ﺮﺑ HTML ﺮﺻﺎﻨﻋ ﻦﺘﻓﺎﯾ

:ﺪﻨﮐ ﯽﻣ ﺍﺪﯿﭘ ﺍﺭ <p> ﺮﺻﺎﻨﻋ ﻪﻤﻫ ﻝﺎﺜﻣ ﻦﯾﺍ

ﻝﺎﺜﻣ

const element = document.getElementsByTagName("p");

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript HTML DOM</h2>

<p>Finding HTML Elements by Tag Name.</p>
<p>This example demonstrates the <b>getElementsByTagName</b> method.</p>

<p id="demo"></p>

<script>
const element = document.getElementsByTagName("p");

document.getElementById("demo").innerHTML = 'The text in first paragraph (index 0) is: ' + element[0].innerHTML;

</script>

</body>
</html>

.ﺪﻨﮐﯽﻣ ﺍﺪﯿﭘ ﺍﺭ <p> ﺮﺻﺎﻨﻋ ﻪﻤﻫ ﺲﭙﺳ ﻭ ،ﺪﻨﮐﯽﻣ

ﻝﺎﺜﻣ

const x = document.getElementById("main");
const y = x.getElementsByTagName("p");

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript HTML DOM</h2>

<div id="main">
<p>Finding HTML Elements by Tag Name</p>
<p>This example demonstrates the <b>getElementsByTagName</b> method.</p>
</div>

<p id="demo"></p>

<script>
const x = document.getElementById("main");
const y = x.getElementsByTagName("p");

document.getElementById("demo").innerHTML = 
'The first paragraph (index 0) inside "main" is: ' + y[0].innerHTML;

</script>

</body>
</html>


ﺱﻼﮐ ﻡﺎﻧ ﺱﺎﺳﺍ ﺮﺑ HTML ﺮﺻﺎﻨﻋ ﻦﺘﻓﺎﯾ

ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻥﺁ ﺯﺍ ،ﺪﯿﻨﮐ ﺍﺪﯿﭘ ﻥﺎﺴﮑﯾ ﺱﻼﮐ ﻡﺎﻧ ﺎﺑ ﺍﺭ HTML ﺮﺻﺎﻨﻋ ﻡﺎﻤﺗ ﺪﯿﻫﺍﻮﺧ ﯽﻣ ﺮﮔﺍ

.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ class="intro" ﺎﺑ ﺍﺭ ﺮﺻﺎﻨﻋ ﻪﻤﻫ ﺯﺍ ﯽﺘﺳﺮﻬﻓ

ﻝﺎﺜﻣ

const x = document.getElementsByClassName("intro");

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript HTML DOM</h2>

<p>Finding HTML Elements by Class Name.</p>
<p class="intro">Hello World!</p>
<p class="intro">This example demonstrates the <b>getElementsByClassName</b> method.</p>

<p id="demo"></p>

<script>
const x = document.getElementsByClassName("intro");
document.getElementById("demo").innerHTML = 
'The first paragraph (index 0) with class="intro" is: ' + x[0].innerHTML;
</script>

</body>
</html>

CSS ﯼﺎﻫﺮﮕﺑﺎﺨﺘﻧﺍ ﻂﺳﻮﺗ HTML ﺮﺻﺎﻨﻋ ﻦﺘﻓﺎﯾ

ﺪﻧﺭﺍﺩ ﺖﻘﺑﺎﻄﻣ ﻩﺪﺷ ﺺﺨﺸﻣ CSS ﺮﮕﺑﺎﺨﺘﻧﺍ ﺎﺑ ﻪﮐ ﺪﯿﻨﮐ ﺍﺪﯿﭘ ﺍﺭ HTML ﺮﺻﺎﻨﻋ ﻡﺎﻤﺗ ﺪﯿﻫﺍﻮﺧ ﯽﻣ ﺮﮔﺍ

.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ class="intro" ﺎﺑ ﺍﺭ

ﻝﺎﺜﻣ

const x = document.querySelectorAll("p.intro");

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript HTML DOM</h2>

<p>Finding HTML Elements by Query Selector</p>
<p class="intro">Hello World!.</p>
<p class="intro">This example demonstrates the <b>querySelectorAll</b> method.</p>

<p id="demo"></p>

<script>
const x = document.querySelectorAll("p.intro");
document.getElementById("demo").innerHTML = 
'The first paragraph (index 0) with class="intro" is: ' + x[0].innerHTML;
</script>

</body>
</html>

HTML Object ﯼﺎﻫ ﻪﻋﻮﻤﺠﻣ ﻂﺳﻮﺗ HTML ﺮﺻﺎﻨﻋ ﻦﺘﻓﺎﯾ

.ﺪﻨﮐﯽﻣ ﺍﺪﯿﭘ ﺎﻫﻡﺮﻓ ﺭﺩ id="frm1" ﺎﺑ ﺍﺭ ﻡﺮﻓ ﺮ

ﻝﺎﺜﻣ

const x = document.forms["frm1"];
let text = "";
for (let i = 0; i < x.length; i++) {
  text += x.elements[i].value + "<br>";
}
document.getElementById("demo").innerHTML = text;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript HTML DOM</h2>
<p>Finding HTML Elements Using <b>document.forms</b>.</p>

<form id="frm1" action="/action_page.php">
  First name: <input type="text" name="fname" value="Donald"><br>
  Last name: <input type="text" name="lname" value="Duck"><br><br>
  <input type="submit" value="Submit">
</form> 

<p>These are the values of each element in the form:</p>

<p id="demo"></p>

<script>
const x = document.forms["frm1"];
let text = "";
for (let i = 0; i < x.length ;i++) {
  text += x.elements[i].value + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>

</body>
</html>

:ﺪﻨﺘﺴﻫ ﯽﺳﺮﺘﺳﺩ ﻞﺑﺎﻗ ﺰﯿﻧ (ءﺎﯿﺷﺍ ﻪﻋﻮﻤﺠﻣ ﻭ) ﺮﯾﺯ HTML ءﺎﯿﺷﺍ