Is it possible to set a src attribute of an img tag in CSS?

Use content:url(“image.jpg”). Full working solution (Live Demo): <!doctype html> <style> .MyClass123{ content:url(“http://imgur.com/SZ8Cm.jpg”); } </style> <img class=”MyClass123″/> Tested and working: Chrome 14.0.835.163 Safari 4.0.5 Opera 10.6 Firefox 100 & newer Tested and Not working: FireFox 40.0.2 (observing Developer Network Tools, you can see that the URL loads, but the image is not displayed) Internet Explorer 11.0.9600.17905 … Read more

How to get the file-path of the currently executing javascript code

Within the script: var scripts = document.getElementsByTagName(“script”), src = scripts[scripts.length-1].src; This works because the browser loads and executes scripts in order, so while your script is executing, the document it was included in is sure to have your script element as the last one on the page. This code of course must be ‘global’ to … Read more

How to properly reference local resources in HTML?

A leading slash tells the browser to start at the root directory. If you don’t have the leading slash, you’re referencing from the current directory. If you add two dots before the leading slash, it means you’re referencing the parent of the current directory. Take the following folder structure notice: the ROOT checkmark is green, … Read more