I am sure that you must familiar with the HTML img tag. We all know that using this tag, we can display an image on a web page. All we have to do is just to give the image path inside the src attribute of the image tag.
Below is an example of how we can show an image on the web page with the HTML img tag:
<img id="my-img" src="cat.png">
var img_src = document.getElementById("my-img").src; console.log(img_src);
If we run our code on the browser, we can see “directory/cat.png” in the console log. You can see that it returns the complete path of the src file.
So easy and simple. Isn’t it? We did it only in one line of code and the extra one line is just to show the value in the console log.