简体   繁体   中英

How do I target this with jQuery? (image)

I am trying to target the blue highlighted line in the image below and prepend a <td> to it.

在此处输入图像描述

I tried...

$('#wpf-wrapper .wpf:nth-child(2) tr:nth-child(2)').prepend('<td class="emblem"></td>');

But it's not working. Am I missing something?

The third child of #wpf-wrapper is not the third .wpf ; it's #trail . Additionally, :nth-child(2) selects the second child, rather than the third.

Use :eq() instead:

$('#wpf-wrapper .wpf:eq(2) tr:nth-child(2)').prepend('<td class="emblem"></td>');

The :nth-child() selector takes into account all children . Try using :eq() instead, which only counts from the result set of the selector.

$(".wpf:eq(1) .forumsList tr:eq(1)").prepend('<td class="emblem"></td>');
$('#wpf-wrapper .wpf').eq(2).find('tr').eq(1).prepend('<td class="emblem"></td>');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM