I created a div with js (var div = document.createElement("div");). Now I want to insert a onclick-function after the div is created. For some reason The onclick-function is triggerd when I click just the playfield.
var create_divs = function(check_if_right_div){
var random_class = Math.floor((Math.random() * 5) + 1);
var id = div_id += 1;
var random_position = 0 + 100*Math.floor(Math.random()*6);
var div = document.createElement("div");
div_id_selection.push('div' + id);
div.className = 'class'+random_class;
div.id = 'div' + id;
div.style.left = random_position;
div.addEventListener("click",check_if_right_div(div));//the function is triggered when I click the playfield, which is a big div that contains the other divs
document.getElementById('play_field').appendChild(div);
var check_if_right_div = function(div_to_check){
var div_class =div_to_check.className;
console.log(div_class);
};
check_if_right_div(div)
does? – Niet the Dark Absol