我希望得到像这样的东西
var argument = $(this).parent().parent().parent().prev().child().attr('ctryid');
这是我想要遍历的部分的剪辑。
我想从newProvButton
转到ctryid
的元素。
一团糟,对不起。
答案 0 :(得分:3)
您可以使用closest()
查找具有给定选择器的相关父元素。试试这个:
var argument = $(this).closest('.expandListContent').prev().find('.expandListHeaderRow').attr('ctryid');
您还应注意,在HTML中使用非规范属性会导致页面无效。请改为使用data-*
属性:
<div class="expandListHeaderRow" data-ctryid="your-guid">Foo</div>
var argument = $(this).closest('.expandListContent').prev().find('.expandListHeaderRow').data('ctryid');
答案 1 :(得分:1)
您可以使用.closest()
:
$(this).closest('.expandListContent').prev().find('div').attr('ctryid');
或
$(this).closest('.expandListContent').prev().find('.expandListHeaderRow').attr('ctryid');