I have to get a far parent's child's child's attribute href...
now i can get that using this long statement
var uid = $(this).parents(':eq(7)').children( ).find('.p_cell')
.children(':eq(0)').children(':eq(0)').attr('hr开发者_运维技巧ef');
please any string using '>' and ' : ' that can simplify the statement
thanks
Pradyut
India
Without knowing the HTML, you can use :first-child
like this:
var uid = $(this).parents(':eq(7)')
.find('> * .p_cell > :first-child > :first-child').attr('href');
If that parent has a class you can access though, instead of say the 8th parent you could find it via a selector that matched using .closest()
. For example if that parent was a <div>
like this:
<div class="container">
You could do this:
var uid = $(this).closest('.container')
.find('> .p_cell > :first-child > :first-child').attr('href');
However, if you posted the HTML this can likely get much simpler.
精彩评论