JavaScript not adding eventlistener
Briefly

The provided code attempts to add a delete button to a cloned table row. However, when the button is clicked, the DeleteRow function fails to execute as intended. The root of the issue stems from the line of code that tries to find the nearest 'tr' element. Instead of using 'nearest', the correct method to access the nearest row is through jQuery's 'closest' function, which should reference the button clicked. Correcting this will ensure that the function works as expected.
The issue lies in the way the DeleteRow function is being invoked. The line 'x.nearest' should instead be '$(x).closest('tr')' to properly find the row containing the button.
Another point of confusion is using 'nearest' instead of 'closest'. The jQuery function closest uses the correct syntax to get the nearest parent element matching a selector.
Read at SitePoint Forums | Web Development & Design Community
[
|
]