I am trying to get the pause button to work in each span separately. Each time the user clicks the "add" button (code not shown), a new <span class="emailform">
set of these elements is appended to the <div class="email">
. I don't know how to attach the click event handler to the pause button in the newly added span of elements. I have attached images so that you can see what I'm trying to do. (I'm prolly using trigger() wrong as well trying to call my own function.)
I've also included a fiddle here.
Thanks for your help!
html:
<div class="email">
<span class="emailform">
<label for="vs-email" class="use-email" >Via email:</label>
<input type="text" class="text-input" />
<input type="button" class="pause" />
<input type="button" class="remove" value="remove" />
</span>
</div>
jQuery:
$(".pause").on('click', function(e){
$(e.target).closest("span").trigger(pauseRestore());
});
function pauseRestore(){
var oddClick = $(this).data("oddClick");
$(this).data("oddClick", !oddClick);
if(!oddClick) {
pauseAction();
}else {
restoreAction();
}
}
Original start (good)
Another added after clicking 'add' button (good)
Click to pause first only (good)
Click to pause new added (BAD, nothing happens)
Click pause button in first span (BAD -- both are now selected and paused)
This is the result I want. When user clicks on the pause button in the new added span, only this is paused, not any others. Each one is separate.