HTML DOM အနီးစပ်ဆုံး() နည်းလမ်း
❮ Element Objectဥပမာ
CSS Selector နှင့် ကိုက်ညီသည့် အနီးစပ်ဆုံး အစိတ်အပိုင်းကို ရှာပြီး အဝါရောင်ဘောင်ကို ပေးလိုက်ပါ။
var element = document.getElementById("myElement");
var closest =
element.closest(".container");
if (closest) {
closest.style.border = "10px solid yellow";
}
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
closest()
နည်းလမ်းသည် သတ်မှတ်ထားသော CSS ရွေးချယ်မှုတစ်ခုနှင့် ကိုက်ညီသည့် အနီးစပ်ဆုံးဒြပ်စင်အတွက် DOM သစ်ပင်ကို ရှာဖွေသည်
။ ၎င်းသည် ဒြပ်စင်ကိုယ်တိုင်မှ စတင်သည်၊ ထို့နောက် ကိုက်ညီမှုတစ်ခုကို ရှာမတွေ့မချင်း မိဘ၊ ဘိုးဘွား စသည်တို့ကို စမ်းသပ်သည်။ ကိုက်ညီမှုတစ်ခုကို ရှာမတွေ့ပါက၊ ဤနည်းလမ်းသည် null ဖြစ်သွားသည် ။
Browser ပံ့ပိုးမှု
ဇယားရှိ နံပါတ်များသည် နည်းလမ်းကို အပြည့်အဝထောက်ခံသည့် ပထမဆုံးဘရောက်ဆာဗားရှင်းကို သတ်မှတ်ပေးသည်။
Method | |||||
---|---|---|---|---|---|
closest() | 41.0 | 15.0 | 35.0 | 6.0 | 28.0 |
အထားအသို
element.closest(selectors)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
selectors |
Required. Specifies one or more CSS selectors to match the element. These are used to select HTML elements based on their id, classes, types, attributes, values of attributes, etc. For multiple selectors, separate each selector with a comma. The returned element depends on which element that is first found in the document. Tip: For a list of all CSS Selectors, look at our CSS Selectors Reference. |
နည်းပညာဆိုင်ရာအသေးစိတ်
ပြန်ပို့တန်ဖိုး- |
သတ်မှတ်ထားသော CSS ရွေးချယ်မှု(များ)နှင့် ကိုက်ညီသော အနီးစပ်ဆုံး ဘိုးဘေးဒြပ်စင် သို့မဟုတ် ဒြပ်စင်ကိုယ်တိုင်။ ကိုက်ညီမှုမတွေ့ပါက null ကို ပြန်ပေးသည်။ သတ်မှတ်ထားသော ရွေးချယ်မှု(များ) မမှန်ကန်ပါက SYNTAX_ERR ခြွင်းချက်တစ်ခုကို လွှင့်ပစ်ပါ။ |
---|
ဆက်စပ်စာမျက်နှာများ
JavaScript ရည်ညွှန်းချက်- element.matches() နည်းလမ်း။
❮ Element Object