Consider below HTML:
<div class="votingButton">
<i class="icon-chevron-up"></i>
</div>
As you can see parent of i
element is div
, but when I try to get parent of i
via jQuery it gives me i
:
$(function () {
$('.icon-chevron-up').on('click', function () {
alert($(this).parent().html());
});
});
Above code gives me <i class="icon-chevron-up"></i>
, I also tried these cases:
$(this).closest('.votingButton').html()
$(this).parents().html()
$(this).parents('.votingButton').html()
But still get <i class="icon-chevron-up"></i>
Any idea?