So I have the following JavaScript function.
var LogoUrl = function() {
document.write('views/img/common/site-logo.svg');
}
And I want to have this function used in a html img src attribute.
Here is a example though this syntax wouldn't work, it should give you an idea of what I am looking for.
<img class="site-logo" src="<script> LogoUrl() </script>" alt="Site Logo">
And hoping this would export the following in the browser
<img class="site-logo" src="views/img/common/site-logo.svg" alt="Site Logo">
What is the best approach to doing this?
srcis required to be a URI. You can't just dump OTHER html into any place you want and expect it to work. If you want to dynamically change the src of an image, then you'll have to run that code ELSEWHERE and find the image in the DOM, then fiddle with that DOM element's src attribute.