I want to be able to add an onclick handler to a dynamically created div.
Here is how I create the elements:
function add_remove_roll_func(){
for (var i = 0; i<3; i++){
li_dice_side_one = createElementWithClass('li',arguments[i]);
add_remove_roll.appendChild(li_dice_side_one);
document.getElementById("ul");
}
}
add_remove_roll = createElementWithOutClass('ul');
dice_toolbar_wrapper_close.appendChild(add_remove_roll);
document.getElementById("dice-content-wrapper");
add_remove_roll_func("add","remove","roll");
I want the add remove and roll events to call different functions.
I tried doing add_remove_roll_func("'add' 'onclick="function'...)
But that did not auto-magically work :).
I could do it with jQuery but I need to do this with native javascript.
What is add_remove_roll_func?!
You need to use addEventListener() in order to add onclick or any other handler to an event. Example: