I am adding new elements through jQuery to some of my projects, and I came across a slightly cumbersome problem.
Consider the following:
$('span.claim').click(function() { $(this).parent().html('<span class="unclaim">Unclaim</span>'): }); $('span.unclaim').click(function() { $(this).parent().html('<span class="claim">Claim</span>'): });
And the next markup ...
<ul> <li><span class="claim">Claim</span></li> <li><span class="unclaim">Unclaim</span></li> <li><span class="claim">Claim</span></li> <li><span class="unclaim">Unclaim</span></li> </ul>
Unfortunately, after the start of the start event, subsequent events are not processed.
I understand that I can completely restructure and use the .bind() function, but due to the complexity of my project, this is actually not all that is possible.
How can I reset events after creating new elements without discarding anonymous functions, or is this possible?
Skudd source share