I have a image in my HTML file like this.
<img src="@routes.Assets.versioned("images/bell.png")" width="200", height="200" id = "symbolImg">
Image file is stored here.
Output
I was trying to change the image by having the following code in a typescript file.
document.getElementById("changeImageBtn").addEventListener("click", function () {
document.getElementById("symbolImg").setAttribute("src", "@routes.Assets.versioned('images/cherry.png')" );
document.getElementById("symbolImg").setAttribute("width", "300");
document.getElementById("symbolImg").setAttribute("height", "300");
});
But the image doesn't change. This is the output.
Edit 1
Also tried these ways with escape characters. Had no effect.
document.getElementById("symbolImg").setAttribute("src", "@routes.Assets.versioned("images/bell.png")" );
.
document.getElementById("symbolImg").setAttribute("src", "@routes.Assets.versioned("images/bell.png")" );
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…