Not getting the image name to append to path

Hello have this bit of code

var imgName = document.createTextNode(currentCard.getElementsByTagName("tnail")[0].firstChild.data);
var imgElem = document.createElement("img");
imgElem.setAttribute("src", ".imgs/core/" + imgName);
imgElem.setAttribute("height", "75");
imgElem.setAttribute("width", "75");
imgElem.setAttribute("alt", "gtdi");
backCard.appendChild(imgElem);					
newCard.appendChild(backCard);
console.log(imgName);

the console.log gives me correct name of the image i place in the xml doc. kitten.png.
but when so far when i go to add it to the path on the code of line with:

imgElem.setAttribute("src", ".imgs/cFolder/" + imgName);

I get the error message:

http://localhost/jscoding/.imgs/cFolder/[object%20Text] 404 (Not Found)

so I see two issues, one. I have not managed to escape the the " delimter & two I don’t see why the console log will give me the right name but other experiments still give me a [object Text]
& getting the kitten.png from an xml file
thx

Never mind. Found the answer.

//append the images
	var imgName = currentCard.getElementsByTagName("tnail")[0].firstChild.nodeValue;
	var textNode = document.createTextNode(imgName);
	//alert(imgName.nodeValue);
	var imgElem = document.createElement("img");
	imgElem.setAttribute("src", "../jscoding/imgs/cFolder/" + imgName);

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.