jquery - How do I remove list items that have been added by append? -


I want to be able to add objects to an unshared list (wibble) when a large list of items (user_checkboxes) Is selected from). If a user clicks on an item in the 'wibble' list, I would like to remove that item from the list.

The problem I have is that the list works as 'A' and 'B' items I was hoping for. That means if I click on the list item, they are removed from the list. Unfortunately, any items that are added to the list from the app do not behave in the same way. That is, they are not selected and removed from the list. & lt; Ul class = "wibble" & gt; & Lt; Li & gt; & Lt; / Li & gt; & Lt; Li & gt; B & lt; / Li & gt; & Lt; / Ul & gt; $ (Document) .ready (function () {$ (". User_checkboxes"). Change (function () {if ($ (this) .attr ("checked")) {$ ('.wibble'). '& Lt; li & gt; '+ newListItem +' & lt; / li & gt; ';)}} $ (' .wibble li '). Click (function () {$ (this) .remove ();) ;}

When you click the click event handler Do not list elements still exist, so jQuery can not bind any handlers with them.

Use instead:

  $ ('.wibble'). Representative ('li', 'click' function () {$ (This) .remove ();});   

This connects an event handler to .wibble (which does Is present) and hears any clicks that arise from the li element of the line.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -