contents method
contents method သည် အစိတ်အပိုင်း၏ ဆင်းသက်သည့်အရာများကို ရယူသည်၊
စာသားနှင့် မှတ်ချက်များလည်း ပါဝင်သည်။
ဝါကျဖွဲ့စည်းပုံ
Method သည် parameter များကို လက်ခံမထားပါ:
.contents();
contents method သည်
children method နှင့် ဆင်တူသည်၊
ကွာခြားချက်သည် ဆင်းသက်သည့်အရာများ၏ စာသားများကို
လက်လှမ်းမီရန် ကြိုးစားသည့်အခါတွင် ပေါ်လာသည်။ အောက်တွင် ဖော်ပြထားသည့်
နမူနာနှစ်ခုကို နှိုင်းယှဉ်ကြည့်ပါ:
နမူနာ
children method ကို အသုံးပြုသည်:
<p id="test">text1 <b>bold</b> text2</p>
$('#test').children().each(
function() {
console.log($(this).text()); // 'bold' ကို ပြသမည်
}
);
နမူနာ
contents method ကို အသုံးပြုသည်:
<p id="test">text1 <b>bold</b> text2</p>
$('#test').contents().each(
function() {
console.log($(this).text()); // 'text1', 'bold', 'text2' ကို ပြသမည်
}
);