Get click element (this) in method

0

I am refactoring a SPA using MVC with classes and etc ...

I made a method that is called when I click on a <i> element and would like to get that element to later delete a relative of it (a <tr> two levels above).

I'm calling this event in HTML with attr onclick="CalculaController.removeLinha()"

But if I ask to get the this it returns me to the controller class and not the element clicked, I did some tests with type .on('click', function(){return this}); event but it did not stay 100% with some errors ...

    
asked by anonymous 01.11.2017 / 12:39

1 answer

2

To get your element in the function you can send it as a parameter to it. Ex:

<i onclick="FuncaoTeste(this);">Teste</i>

var FuncaoTeste = function(element)
{
    console.log(element);
}

If you're interested, take a closer look at the workings of this .

    
01.11.2017 / 13:29