Hi everybody,
I am trying to extend the JavaScript's native class Element as below. If I then create two or more distinct objects, assigning values to any of them affects all the objets as if they were referencing one and the same object. However, div1 == div2 throws false. Could anybody explain why is that and how to fix this issue?
Thanks!
I am trying to extend the JavaScript's native class Element as below. If I then create two or more distinct objects, assigning values to any of them affects all the objets as if they were referencing one and the same object. However, div1 == div2 throws false. Could anybody explain why is that and how to fix this issue?
Code:
function Div()
{
//Empty
}
Div.prototype = document.createElement("DIV");
var div1 = new Div();
var div2 = new Div();
div1.style.border = "solid 1px black";
div2.style.border = "dashed 4px red";
document.body.appendChild(div1);
Comment