4
I have the following elements:
<p class="id-task">5</p>
<p class="status-change">
<i id="test-task" class="fa fa-flask fa-lg" aria-hidden="true"></i>
</p>
I’m trying to get number 5 in <p class="id-task">5</p>
with the following Jquery code:
$('#test-task').on('click', function(){
var father = $(this).parent().siblings();
var idTask = $(father).text();
alert(idTask);
});
I changed the code, because the parent()
end has to be .siblings()
, because the <p class="id-task">5</p>
is the brother of <p class="status-change"></p>
I would use something like var id = $(this). Parent(). Parent(). find('id-task'). text();
– Bartolomeu S. Gusella
there can be several elements with the class "id-task".
– tomasantunes