How to paste element by Jquery id? [duplicate]

0

I have the following HTML code generated by PHP:

<li id="15" data-status="Em Processo" class="list-group-item tasks-list-group">
    <p style="display: none">#15</p>                                                                            
    <span class="badge" style="background-color:#67A6DF">Processo</span>                                    
    08/12/2016<br>
    Teste 2                                     
    <p style="display: none">Média</p>
    <p class="fantasy">Teste</p>
    <div class="type-average"></div>
    <i class="fa fa-flask fa-lg test-task" aria-hidden="true"></i>                                  
    <i class="fa fa-times fa-lg cancel-task" aria-hidden="true"></i>
</li>

When I click on <i class="fa fa-flask fa-lg test-task" aria-hidden="true"></i> it should change the status of the task to Test .

But I need to get the ID of the tag li , but I can not get to .parent() , because the sequence of HTML elements changes.

But I tried the following:

$(".test-task").on('click', function(){
    var element = $(this).find('.tasks-list-group').attr('id');    
    var idTask = $(element).val();   
    alert(idTask);  
});

But returns undefined.

Does anyone have any idea what I can do?

    
asked by anonymous 08.12.2016 / 14:53

1 answer

1

You can get hold of .parents () regardless of the order and number of elements. As long as the father is always a li:

var $parent = $(this).parents('li');

link

    
08.12.2016 / 14:55