What is the correct way to style an HTML canvas element via a function that takes any style rule and value as parameters? Yes I know a direct Javascript approach would work. The setCSS() function is a testbed for a version 2 setCSS() function that is intended to set multiple css styles by utilizing an array of objects (key, values) as parameters such that each object represents a single CSS property. Here is what I have that is not working:
function init() {
'use strict';
let can = document.getElementById('canvas');
let ctx = canvas.getContext('2d');
resizeBlock(can, 50, 50);
// Tried both forms individually by commenting out other function
setCSS(can, 'borderWidth', '20px');// not working
setCSS(can, 'borderWidth', '20');// not working
}
function setCSS(element, rule, value) {
element.style.rule = value;
return element; // should element return or not?
}