I have some checkboxes. When I select one of them I need to add a new element to a list.
I have implemented a change function in jQuery. When I select a checkbox, it adds the element in the list like I want, but when I unselect it, it doesn’t remove the element.
The list id is sumary and the checkbox and the element in the list have the same attribute name.
To remove I have tried this but it doesn’t work:
$("#sumary").find("li[name=$(this).attr('name')]").remove();
If I hardcode a value for $(this).attr('name') it works so the problem is with this:
$(this).attr('name')
What is the solution?
Javascript doesn’t parse variables within strings, so you’ll want to concatenate the variable into it. Try: