Steve Gates
Steve Gates

Reputation: 195

Making button call multiple functions

Does anyone have a clue on how I can solve this please? Answer below doesn't work.

I googled this question and found lots of answers but not suited to my problem.

I am trying to make a button call multiple functions (2 to be exact):

JS

  $(window).load(function(){
  $(function() { 
    $(".btn").click(function() { 
        html2canvas($(this).next(), {
            onrendered: function(canvas) {
                theCanvas = canvas;
                document.body.appendChild(canvas);

                canvas.toBlob(function(blob) {
          saveAs(blob, "Dashboard.png"); 
        });
            }
        });
    });
}); 
});
  $('.btn').on('click', function(){
   $('canvas').appendTo('#here');  // appendTo -> selector
});

HTML

<a href="#" class="btn">Click</a>

I've tried the following: 1. Call two functions from same onclick 2. Can i append an already existing div to another already existing div?

Which really sums up every other answer.

Any suggestions?

Upvotes: 2

Views: 141

Answers (1)

Peter
Peter

Reputation: 447

$(function(){
    $('.btn').on('click'(function(){
        callFunction1();
        callFunction2();
    });
});

function callFunction1(){
   $('#yourDivId').appendTo('#yourOtherDivId');
   console.log("what should function 1 do?");
}

function callFunction2(){
   console.log("What should function 2 do?");
}

Upvotes: 4

Related Questions