$(this).parents('table:first > tbody > tr')
औरइन दो चयनकर्ताओं के बीच क्या अंतर है?
$(this).parents('table:first').children('tbody').children('tr')
$(this).parents('table:first > tbody > tr')
औरइन दो चयनकर्ताओं के बीच क्या अंतर है?
$(this).parents('table:first').children('tbody').children('tr')
अंतर यह है कि पहले चयनकर्ता, parents
कॉल के भीतर पूरी तरह से है, जबकि दूसरा एक नहीं है।
इसलिए, पहला व्यक्ति this
के सभी माता-पिता को देखता है जो table:first > tbody > tr
से मेल खाते हैं। (दूसरे शब्दों में, एक tr
this
युक्त पहला table
में है)
दूसरा एक जो table:first
से मेल खाता है this
की मूल मिलेगा, तो सीधे कि माता पिता की tbody
रों भीतर tr
रों के सभी पाते हैं। (दूसरे शब्दों में, सीधे tr
रों माता पिता तालिका के अंदर के सभी)
काउंटर अंतर्ज्ञानी लगता है। मैंने पहले बिल्कुल बिल्कुल पढ़ा। बेशक मैं परीक्षण करने के लिए बहुत आलसी हूँ। – ChaosPandion
@ChosPandion: उन्हें और अधिक सावधानी से पढ़ें। आप देखेंगे कि मेरा क्या मतलब है। – SLaks
+1 - ठीक है, मैंने ध्यान से देखा है और मुझे अंततः यह मिला। – ChaosPandion
हो सकता है कि एक उदाहरण में मदद मिलेगी ... इस HTML के साथ शुरू
<table border=1>
<thead>
<th>Outter Table</th>
</thead>
<tbody>
<tr><td>1</td></tr>
<tr>
<td>
<table border=1 width=100>
<thead>
<th>Inner Table</th>
</thead>
<tbody>
<tr><td>2a</td></tr>
<tr><td class="test">2b</td></tr>
<tr><td>2c</td></tr>
</tbody>
</table>
</td>
</tr>
<tr><td>3</td></tr>
</tbody>
</table>
इस स्क्रिप्ट लागू करें:
$('.test').parents('table:first > tbody > tr').addClass('foo');
$('.test').parents('table:first').children('tbody').children('tr').addClass('bar');
परिणाम:
<table border="1">
<thead>
<th>Outter Table</th>
</thead>
<tbody>
<tr class="foo"><td>1</td></tr>
<tr class="foo">
<td>
<table width="100" border="1">
<thead>
<th>Inner Table</th>
</thead>
<tbody>
<tr class="bar"><td>2a</td></tr>
<tr class="bar"><td class="test">2b</td></tr>
<tr class="bar"><td>2c</td></tr>
</tbody>
</table>
</td>
</tr>
<tr class="foo"><td>3</td></tr>
</tbody>
</table>
यह भी अच्छा है! – user198729
उपयोग नहीं बल्कि माता-पिता और की तुलना में सबसे करीब: पहला – redsquare
@redsquare: हम नहीं जानते कि वह वास्तव में क्या चुनने की कोशिश कर रहा है। – SLaks
निकटतम == माता-पिता ('तालिका: पहला') – redsquare