Skip to content
Advertisement

remove a especific tr child of a table

EDIT: I forgot to mention that those TR were created dynamically.

I’m trying to remove a especific TR that is inside a <tbody> when I click in the red X. I can identify the line I just cant remove it.

What I tried:

JavaScript

AND

JavaScript

Any tips on how to select the corret TR? Ill post what i have.

JavaScript
JavaScript

Advertisement

Answer

First of all, It’s not oneclick, but onclick.

JavaScript

That said, the event (e) thats passed to the function can be used to get the desired output.

JavaScript

Will get the paret node (tr) of the cell (td), and remove it as you can test here:

JavaScript
JavaScript

We can use that Javascript call on the onclick itself so we don’t need the function. Change the event (e) to the current element this:

JavaScript

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement