Making this javascript code n8n fiendly

var shownImg = document.getElementsByTagName("img");

I am looking to replace this line with something that checks the previous node and looks for the “img” in the html that is part of the json response.

This is the full code:

const response = [];

let myOwnImgs= ['HXXP://', 'HXXP://']

var shownImg = document.getElementsByTagName("img");

for(var i =0; i< shownImg.length; i++){
  shownImg[i].src = myOwnImgs[i]  // updating main image with array image
  shownImg[i].alt = myOwnImgs[i].slice(-7)  // for verifying

    json: {

return response;

basically, I feel like it should be something like

var shownImg =  **REFERENCE TO JSON NODE HERE** .getElementsByTagName("img");

and I need to also replace this with an array list from the previous json node

let myOwnImgs= ['HXXP://', 'HXXP://']

or something close to that, any ideas?

The idea here is to replace img URLs in HTML with a list of my own urls

Hey @RedPacketSec,

Do you have an example of the data you are replacing in? The getTagElementsByTagName won’t work as I think that is designed to be used in a client / browser. My initial thought is maybe using HTML Extract with a code node to do a replace would do the job.

yeah i have already done a html to get to this point, and this is a function node so basically sounds like what you were saying.

Yeah I had a feeling that was browser only, but not sure what works or doesn’t in n8n.

You can use any website as example data and just look to replace the img with an image URL of your own etc