0

This JS code failed to show the image, instead it gives the string [object HTMLImageElement].
How can it be fixed so that it shows the image in this location? Thanks

let signature = $('canvas.signature').get(0).toDataURL(); //earlier in the code

let w = window.open();
let doc = w.document;
doc.write(html);
doc.close();
let sigImg = new Image();
sigImg.src = signature;
let nodes = doc.querySelectorAll('td.Label');
for (var i = 0; i < nodes.length; i++) {
  var item = nodes[i];
  if (item.textContent === "User's signature:") {
    item.nextElementSibling.innerHTML = sigImg; //<--- failed to show the image
  }
}

edit
The reason I did not use item.nextElementSibling.appendChild(sigImg); is because I wanted to replace the content of the td element with the image. but even with this solution, I get a small icon, which when right click and open in new page, I get (This site can’t be reached).

1 Answer 1

2

The problem is with this

item.nextElementSibling.innerHTML = sigImg;

... change to

item.nextElementSibling.innerHTML = ''; // clear contents
item.nextElementSibling.appendChild(sigImg);

sigImg is an object, you'll find you get [object Object] displayed instead with your code, I assume

Sign up to request clarification or add additional context in comments.

1 Comment

oh, you want to replace the content of nextElementSibling?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.