I want to delete a div with a dynamically created id.
i capture the id via the attr i.e
var rowToDelete = $(this).attr('data-name');
I then tried this:
$(# " + rowToDelete + ").remove();
and this:
$(#rowToDelete").remove();
none worked. I am not concatenating the values correctly.
How do I correctly concatenate the value to the ‘#’ .
2
Answers
You are messing up quotes, so there is syntax errors, check console.
You only need to quote
#
character (assumingdata-name
contains valid ID reference):You have to set # Selector as static string & rowToDelete variable as dynamic, like this :
OR
You can use template literals, like this :