closest()
पहला तत्व प्राप्त करेगा जो तत्व का परीक्षण करके चयनकर्ता से मेल खाता है और डीओएम पेड़ में अपने पूर्वजों के माध्यम से आगे बढ़ता है। लेकिन मैं जानना चाहता हूं कि परिणाम प्राप्त करने का कोई तरीका है (मेरा मतलब है कि सिर्फ इसके माता-पिता प्राप्त करें)? धन्यवाद।jquery निकटतम स्वयं को बाहर निकालें
मुझे एक उदाहरण लेने दो। कृपया इसकी समीक्षा करें।
<div id='div1' class="container">
<div id="div2" class="container">
<!--many nested div.container as it directly or indirectly children -->
</div>
<div id="div3" class="container">
<!--many nested div.container as it directly or indirectly children -->
</div>
</div>
$(function() {
$('div.container').on('mouseover', function(e){
//I only want to select the first parent with the class container.
//closest include the this element.
console.log($(this).closest('.container').attr('id'));
});
});
और अधिक समझा सकता है? कोड स्निपेट जोड़ना अधिक सहायक होगा ... – Reigel
'.parents() 'मदद करेगा। –
@Reigel क्या आप इसे फिर से समीक्षा कर सकते हैं? मैंने अपडेट किया था। धन्यवाद। –