I have a node: <div id = "box1" class = "box center green size200"></div>
I have this event handler:
document.body.addEventListener("click", function(event) {
figureObject.createOutline(event.target);
});
I also have a function in a figureObject called createOutline which looks like this: (ifOutline is a variable in the object which keeps track if the figure is selected or not(outlined).
if(this.ifOutlined == false) {
elem.classList.add('selected');
this.ifOutlined = true;
} else if(this.ifOutlined == true) {
elem.classList.remove('selected');
this.ifOutlined = false;
}
Then i have a css selector that looks like this:
.selected {border: 2px solid black;}
I duplicate the box1 element(which is the original element on the screen) using:
var clone = box1.cloneNode();
var parent = clone.parentNode;
parent.appendChild(clone);
The event handler works fine on the first figure that is on the screen(a green square). But the clone that is created after the duplication will not respond to the event handler, why does this happen?