Skip to content
GitHub

What Is the DOM?

DOM ဆိုတာ Document Object Model ပါ။ စာတွေ့တွေ ထားလိုက်ပါဦး။ ရိုးရိုးလေးပဲ ရှင်းပြမယ်။

သင်ရေးလိုက်တဲ့ HTML Code တွေကို Browser က ဖတ်ပြီး သူ့ရဲ့ Memory ထဲမှာ Tree (သစ်ပင်ပုံစံ) Structure တစ်ခု ဆောက်လိုက်ပါတယ်။ အဲဒါကို DOM လို့ ခေါ်တာပါ။

Javascript က HTML ကို တိုက်ရိုက် မပြင်ပါဘူး။ ဒီ DOM Tree ကြီးကို လှမ်းပြင်တာပါ။ DOM ကို ပြင်လိုက်ရင် Browser မှာ မြင်ရတဲ့ ပုံစံလည်း လိုက်ပြောင်းသွားပါတယ်။

Tree Structure (အပင်ပုံစံ)

Section titled “Tree Structure (အပင်ပုံစံ)”

အောက်က HTML ကို ကြည့်ကြည့်ပါ။

<html>
<body>
<h1>Hello</h1>
<p>World</p>
</body>
</html>

DOM Tree မှာ ဒီလို ဖြစ်သွားပါမယ်။

  • document (အမြစ်)
    • <html>
      • <body>
        • <h1> -> “Hello”
        • <p> -> “World”

JavaScript က ဒီ h1, p စတာတွေကို လှမ်းခေါ်ပြီး စာပြောင်းမယ်၊ အရောင်ပြောင်းမယ်၊ ဖျက်ပစ်မယ်။ ဒါကို DOM Manipulation လို့ ခေါ်တာပါ။