I’m using javascript to reach img elements nested in some <div>.After that I want to add those images to a string variable.
I wrote that:
var SomeVariable="";
$("myDivId img").each(function(){
console.log(this);
SomeVariable += this;
});
console.log(SomeVariable);
When console.log is used in .each function, it shows something like:
<img (some elements)>, which is exactly what I want.
When I use console.log at the end, to write whole value, it says:
[object HTMLImageElement][object HTMLImageElement]
I tried to use some conversion, but I don’t really know how to get to it.
Assuming you want the string representation of their HTML…
If you’re only supporting browsers which have the
outerHTMLproperty.The reason you get
"[object HTMLImageElement]"is because anObject‘stoString()will give you"[object x]", wherexis the[[Class]](an internal property) of the object.