I need to draw a canvas for each element of the matrix, but I do not draw anything with the foreach, but if I take out the foreach and the function per and I only leave the drawing of #nodes if it works, but clearly it only draws me once.
b = [1,2,3,4,5];
$(document).ready(function(){
function per() {
console.log("per()");
$('#nodes').css({
'border-radius': '5px',
'padding': '0',
'margin': '0',
'width': '200px',
'height': '200px',
'position': 'absolute',
'right': '15px',
'bottom': '15px'
});
}
$('body').append('<canvas id="minimap"></canvas><canvas id="nodes"></canvas>');
$('#minimap').css({
'background': 'rgba(1,1,1,0.7',
'border-radius': '0px',
'border': '1px solid rgba(255,255,255,0.2)',
'padding': '0',
'margin': '0',
'width': '200px',
'height': '200px',
'position': 'absolute',
'right': '15px',
'bottom': '15px'
});
b.forEach(per);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
New problem: the answer of asier serves me, the problem is that then I have a function outside of all this code that makes a document.getElementById, I tried doing document.getElementById ($ canvas); but it did not work for me, what should I do?
function per () { for (var i = 0; b [i]; i ++) { var $ canvas = $ (""). css ({ // BLA bla }
}