innerHTML exist but doesn't want write it to other div, other elements are

79 Views Asked by At

I have object with a name of img, and it's taken from DOM, throught onClick function(this) like this:

var img = e.lastElementChild;

and printing of object returns this (only innerHTML i am giving here):

value: <img src="images/p/Ds35.png" alt="C 1" title="C 1" width="500" height="435" itemprop="image" data-highres="http://www.my domain.com/images/o/Ds35.png">

and when i try to put this inner in to the other div like this:

var box = document.getElementById('GP');
box.innerHTML = img.innerHTML;

it's not working, but when i do this:

box.innerHTML = img.src;

it is working... what is going on?

2

There are 2 best solutions below

1
On

there is no innerHTML for <img /> container.

for example innerHTML for <div>test</div> is a string "test"

so try to use img.toString()

0
On

I have found the solution.

img.outerHTML

this one works.

Thanks for trying to help me.