I have a variable when i write its value using document.write() i don’t get the true value. See this-
<div onclick="a=this;document.write(a)">this is div</div>
With this by clicking div i get this[object HTMLDivElement]. But this not the true value see how-
<button onclick="[object HTMLDivElement].style.visibility='hidden'">click me</button>
when i used this code. I expected that it will hide all div elements. But i didn’t got that. Why?
Note:-
i don’t want a better way to do this, i want to know the problem in my code.
Passing an object to
document.writewill convert the object to a string by calling.toString().When called on a
<div>DOM element,toString()returns"[object HTMLDivElement]".This is just a string representation of the object; it is fundamentally impossible to retrieve the original object from that string.