0

I have a button:

   <div id="save-submit" class="save-submit">
            Submit Code
        </div>

When its clicked it checks for an input, if the input is correct i rename the button to continue:

 $('.save-submit').click(function(e){
  var button = document.getElementById("save-submit");
                    button.className="next-task";
                    button.innerHTML="Continue";
                    button.id="next-task-id";
   });

When the continue button is pressed it should load new tasks, but its going back to the save-submit aka trying to rename the button.

 $('.next-task').on('click', function (e) {
        e.preventDefault();
        GetTask();
 });

What am i doing wrong?

Thanks!

user3844579
  • 485
  • 1
  • 8
  • 29
  • Why should it load a different page? There's no code here to do that. You have a click handler which changes the class name, the inner HTML, and the id. It's going to do exactly that any time you click it. – David Dec 26 '16 at 23:22
  • if you want to redirect then check this . http://stackoverflow.com/questions/503093/how-do-i-redirect-to-another-page-in-jquery – Abdullah Mallik Dec 26 '16 at 23:22
  • edited with next-task code – user3844579 Dec 26 '16 at 23:25
  • @user3844579: The cause of your issue is slightly different than the linked duplicate, but the issue itself is the same. You're simply not dynamically *adding* elements, but instead you're dynamically *changing* them. Same net result. – David Dec 26 '16 at 23:27
  • @David so i should use $('.save-submit').on('click',function(e) ? – user3844579 Dec 26 '16 at 23:38
  • 1
    @user3844579: No, that would have the exact same issue for the exact same reason. The `$('.save-submit')` selector is still being used to identify the element for the event handler. This blog post might help explain the difference as well: http://publicvoidlife.blogspot.com/2014/03/on-on-or-event-delegation-explained.html – David Dec 26 '16 at 23:42

0 Answers0