var id = ""; function onClick(td_id) { if (id) { color(id, "", ""); } id = td_id; color(id, "red", "green"); } function color(what, how, self) { switch (what) { {% for ident, connected in complement_position.items %} case "{{ ident }}": {% for i in connected|hash:0 %} document.getElementById("{{ i }}").style.backgroundColor = how; {% endfor %} {% for i in connected|hash:1 %} document.getElementById("{{ i }}").style.backgroundColor = self; {% endfor %} break; {% endfor %} } }