Skip to content Skip to sidebar Skip to footer

How To Use Same Script.js File For Calling Different Css Class Using Multiple Ids

I've made a page where same donut chart will come 4 times. And there size will be same. But there position will be different. One should take atleast 20px space from another. For t

Solution 1:

If I understood you correctly your problem is that you're drawing in a hardcoded canvas element. Parametrise your drawer and call it two times with different id. Change your script according to this pattern

function drawInCanvas(id){
  var myCanvas = document.getElementById(id);
  myCanvas.width = 50;
  myCanvas.height = 40;

  // and the rest of the code...
}

drawInCanvas("myCanvas1");
drawInCanvas("myCanvas2");

Post a Comment for "How To Use Same Script.js File For Calling Different Css Class Using Multiple Ids"