Reputation: 4189
I want to achive something like this
var argument = $(this).parent().parent().parent().prev().child().attr('ctryid');
here is a snip of the section I want to traverse.
I want to go from newProvButton
to the element with ctryid
.
its a mess, im sorry.
Upvotes: 0
Views: 417
Reputation: 337570
You can use closest()
to find the related parent element with the given selector. Try this:
var argument = $(this).closest('.expandListContent').prev().find('.expandListHeaderRow').attr('ctryid');
You should also note that using non-spec attributes in your HTML will render your page invalid. Use a data-*
attribute instead:
<div class="expandListHeaderRow" data-ctryid="your-guid">Foo</div>
var argument = $(this).closest('.expandListContent').prev().find('.expandListHeaderRow').data('ctryid');
Upvotes: 3
Reputation: 82241
You can narrow down the selector using .closest()
:
$(this).closest('.expandListContent').prev().find('div').attr('ctryid');
or
$(this).closest('.expandListContent').prev().find('.expandListHeaderRow').attr('ctryid');
Upvotes: 1