Just use the .closest() method: $(this).closest('.li').remove();
It starts with the current element, and then goes up the chain, looking for a suitable element, and stops as soon as it finds it.
.parent() refers only to the direct parent of the element, i.e. div.msg-modification , which does not match .li . That way, it never reaches the item you are looking for.
Another solution besides .closest() (which checks the current element and then goes up the chain) will use .parents() - however, this would be a warning that it does not stop as soon as it finds the corresponding element (and it does not check the current element, but only the parent elements). In your case, this does not really matter, but for what you are trying to do, .closest() is the most suitable method.
Another important thing:
NEVER use the same identifier for multiple elements. This is not allowed and causes very difficult to debug problems. Remove id="191" from the link and, if you need to access the identifier in the click handler, use $(this).closest('.li').attr('id') . Actually, it would be even cleaner if you used data-id="123" and then .data('id') instead of .attr('id') to access it (so your element id should not remind any row id (database?))
ThiefMaster Jul 11 2018-11-11T00: 00Z
source share