I would like to add an x button to every <li> I have in my <ul>. This x (close) button will delete that individual <li> from the <ul>. How do I do this using jQuery to create a single function that takes the this to delete the current item?
Heres my example HTML:
<ul id="list_a">
<li value="1">Red <span class="closeButton">X</span></li>
<li value="2">Orange <span class="closeButton">X</span></li>
<li value="3">Green <span class="closeButton">X</span></li>
</ul>
edit: added close button <span>
Event delegation. Select the list, then ask it to listen to click events on the
.closeButtons. Then remove thelior the parent of thespan.