find image src that :contains?

You need to use the *= selector: jQuery(‘#preload img[src*=”green”]’) If you want it to be case insensitive, it will be a bit more difficult: var keyword = “green”; $(“#preload img”).filter(function(keyword) { return $(this).attr(“src”).toLowerCase().indexOf(keyword.toLowerCase()) != -1; });

What is my script src URL?

Put this in the js file that needs to know it’s own url. Fully Qualified (eg http://www.example.com/js/main.js): var scriptSource = (function(scripts) { var scripts = document.getElementsByTagName(‘script’), script = scripts[scripts.length – 1]; if (script.getAttribute.length !== undefined) { return script.src } return script.getAttribute(‘src’, -1) }()); Or As it appears in source (eg /js/main.js): var scriptSource = (function() … Read more

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

Add transition while changing img src with javascript

You want a crossfade. Basically you need to position both images on top of each other, and set one’s opacity to 0 so that it will be hidden: <div id=”container”> <img class=”hidden image1″ src=”http://www.istockphoto.com/file_thumbview_approve/4629609/2/istockphoto_4629609-green-field.jpg”> <img class=”image2″ src=”http://www.istockphoto.com/file_thumbview_approve/9958532/2/istockphoto_9958532-sun-and-clouds.jpg” /> </div> CSS: .hidden{ opacity:0; } img{ position:absolute; opacity:1; transition:opacity 0.5s linear; } With a transition set for … Read more

Get img src with PHP

Use a HTML parser like DOMDocument and then evaluate the value you’re looking for with DOMXpath: $html=”<img id=”12″ border=”0″ src=”https://stackoverflow.com/images/image.jpg” alt=”Image” width=”100″ height=”100″ />”; $doc = new DOMDocument(); $doc->loadHTML($html); $xpath = new DOMXPath($doc); $src = $xpath->evaluate(“string(//img/@src)”); # “https://stackoverflow.com/images/image.jpg” Or for those who really need to save space: $xpath = new DOMXPath(@DOMDocument::loadHTML($html)); $src = $xpath->evaluate(“string(//img/@src)”); And … Read more

Javascript : get src and set as variable?

As long as the script is after the img, then: var youtubeimgsrc = document.getElementById(“youtubeimg”).src; See getElementById in the DOM specification. If the script is before the img, then of course the img doesn’t exist yet, and that doesn’t work. This is one reason why many people recommend putting scripts at the end of the body … Read more