To get img element src and set as variable with JavaScript, we get the src
property.
For instance, we write
const imgSrc = document.getElementById("some-img").src;
to select the img element with getElementById
.
And then we get its src attribute value with the src
property.
If src attribute has a relative path, then the src
property would be the resolved path.
Conclusion
To get img element src and set as variable with JavaScript, we get the src
property.