user7167236 user7167236 - 5 months ago 37
Javascript Question

How to modify clickable elements in jQuery?

Why doesn't the on click listener work after clicking on the first list-button?

JSFiddle link

$(".acceptTask").on("click", function(){

$(".solveTask").on("click", function() {

function solveTask(e){

function acceptTask(e){
$(document).on("click", ".solveTask", solveTask);


$('.solveTask').on('click', /*...*/) only applies the event handler to anything that has a class "solveTask" at that time. So when you add the solveTask class in your acceptTask function, add an event listener.

$(e).addClass('btn-warning solveTask')
    .click(function () { solveTask(this); });

See fiddle: