jQuery fatherUntil() နည်းလမ်း
❮ jQuery ဖြတ်သန်းခြင်းနည်းလမ်းများ
ဥပမာ
<span> နှင့် <div> ကြားရှိ ဘိုးဘေးအရာအားလုံးကို ပြန်ပေးပါ။
$(document).ready(function(){
$("span").parentsUntil("div").css({"color": "red", "border": "2px solid red"});
});
ရလဒ်:
body (great-great-grandparent)
div (great-grandparent)
ul (grandparent)
- li (direct parent)
span
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
မိဘများUntil() method သည် selector နှင့် stop ကြားရှိ ဘိုးဘေးဒြပ်စင်အားလုံးကို ပြန်ပေးသည် ။
ဘိုးဘွားများသည် မိဘ၊ ဘိုးဘွား၊ အဘိုးအဘွား စသည်တို့ဖြစ်သည်။
DOM သစ်ပင်- ဤနည်းလမ်းသည် DOM ဒြပ်စင်များ၏ ဘိုးဘေးများတစ်လျှောက်၊ စာရွက်စာတမ်း၏ အမြစ်ဒြပ်စင်အထိ၊ ၎င်းသည် သီးခြားဒြပ်စင်တစ်ခုသို့ ရောက်သည်အထိ ဤနည်းလမ်းသည် ပင်မဒြပ်စင်မှ အထက်သို့ ဖြတ်သန်းသည်။
မှတ်ချက်- ကန့်သတ်ဘောင်နှစ်ခုလုံးသည် ဗလာဖြစ်နေပါက၊ ဤနည်းလမ်းသည် ဘိုးဘေးဒြပ်စင်များ ( မိဘများ() နည်းလမ်းအတိုင်း) အားလုံးကို ပြန်ပေးပါမည်။
ဆက်စပ်နည်းလမ်းများ-
- parent() - ရွေးချယ်ထားသော ဒြပ်စင်၏ တိုက်ရိုက် ပင်မဒြပ်စင်ကို ပြန်ပေးသည်။
- မိဘ() - ရွေးချယ်ထားသော ဒြပ်စင်၏ ဘိုးဘေးဒြပ်စင်အားလုံးကို ပြန်ပေးသည်။
- အနီးစပ်ဆုံး() - ရွေးချယ်ထားသော ဒြပ်စင်၏ ပထမဆုံးဘိုးဘေးကို ပြန်ပေးသည်။
အထားအသို
$(selector).parentsUntil(stop,filter)
Parameter | Description |
---|---|
stop | Optional. A selector expression, element or jQuery object indicating where to stop the search for matching ancestor elements |
filter | Optional. Specifies a selector expression to narrow down the search for ancestors between selector and stop Note: To return multiple ancestors, separate each expression with a comma. |
သင်ကိုယ်တိုင်စမ်းကြည့်ပါ - ဥပမာများ
ကို စစ်ထုတ်ရန် ကန့်သတ်ချက်များ နှစ်ခုလုံးကို မည်သို့အသုံးပြုရမည်နည်း။
<span> နှင့် <body> အကြား ဘိုးဘေးများစွာကို မည်သို့ပြန်ဆိုရမည်နည်း။
သည် DOM ဒြပ်စင်ကို အသုံးပြု၍ <span> နှင့် <div> ကြားရှိ ဘိုးဘေးအားလုံးကို ပြန်ပေးသည်။
အသုံးပြု၍ ဘိုးဘေးရှာဖွေမှု <ul> ဒြပ်စင်များကို <span> နှင့် <div> ကြားတွင် ကျဉ်းမြောင်းစေရန် DOM ဒြပ်စင်ကို အသုံးပြုခြင်း။
❮ jQuery ဖြတ်သန်းခြင်းနည်းလမ်းများ