Alright, so I've got a parent div with child divs. JavaScript is responsible for creating the child divs, giving them unique IDs and text content. My current task involves adding functionality to these items - specifically, I want to add an 'X' button behind each item that, when clicked, will remove the respective item. Is this achievable? I've made an attempt using JavaScript but struggled to figure out how to link the click event on the 'X' to the removal of the item. Additionally, the removal process should also target and remove a specific class associated with that particular item. Below you'll find a snippet of the code.
Here's an example of the HTML structure:
<div id="itemcart" style="float: left;height: 184px;width: 330px;left: 245px;">
<div id="★_Butterfly_Knife__Crimson_Web_Field-Tested">★ Butterfly Knife | Crimson Web (Field-Tested)</div>
<div id="AWP__Asiimov_Battle-Scarred">AWP | Asiimov (Battle-Scarred)</div>
<div id="AK-47__Wasteland_Rebel_Field-Tested">AK-47 | Wasteland Rebel (Field-Tested)</div>
<!-- more div elements here -->
</div>
The child divs within the 'itemcart' are dynamically added by JavaScript in response to clicking an "item-card". These cards pull names from the image titles. When an item-card is clicked, it adds the class "item-selected". What I'm aiming for is to have the ability to not only delete an item by clicking on it but to also remove the corresponding "item-selected" class from the relevant item card simultaneously. Can this be achieved?