function getNextCanvas(currentCanvas) { var elements = document.getElementsByTagName('canvas'); for(var i = 0; i < elements.length; i++) { if (currentCanvas === elements[i]) { return elements[i + 1] || null; } } return null; }