Fallback (default) image using Angular JS ng-src

I’m trying to set an image source using data returned from a modal. This is inside an ng-repeat loop: <div id=”divNetworkGrid”> <div id=”{{network.id}}” ng-repeat=”network in networks”> <span> <table> <tr> <td class=”imgContainer”> <img ng-src=”{{ (‘assets/img/networkicons/’+ network.actual + ‘.png’) || ‘assets/img/networkicons/default.png’ }}”/> </td> </tr> </table> </span> </div> </div> As is apparent, I want to populate default.png when … Read more

JavaScript – Get size in bytes from HTML img src

I would like to know how to get the size in bytes from the “src” from an “img” tag with HTML/JS. <img src=”https://ofbuckleyandbeatles.files.wordpress.com/2011/01/testpattern.gif”/> In the above example I would basicly want to know how big “testpattern.gif” is (in bytes). Thanks in advance. Answer Well, this is 2017 and you can now use Resource Timing API … Read more

changing the img src with jquery

The html structure I have is something like: <ul id=”something”> <li> <a href=””> <img src=”http://domain.com/directory/file1-128×79.jpg”> </a> </li> <li> <a href=””> <img src=”http://domain.com/directory/file2-128×79.jpg”> </a> </li> <li> <a href=””> <img src=”http://domain.com/directory/file3-128×79.jpg”> </a> </li> </ul> I’m trying to change the filename from file#-128×79.jpg to file#-896×277.jpg. I don’t know how to take the dynamically generated filename and search and … Read more

Matching SRC attribute of IMG tag using preg_match

I’m attempting to run preg_match to extract the SRC attribute from the first IMG tag in an article (in this case, stored in $row->introtext). preg_match(‘/\< *[img][^\>]*[src] *= *[\”\’]{0,1}([^\”\’]*)/i’, $row->introtext, $matches); Instead of getting something like images/stories/otakuzoku1.jpg from <img src=”images/stories/otakuzoku1.jpg” border=”0″ alt=”Inside Otakuzoku’s store” /> I get just 0 The regex should be right, but I … Read more

Pass vars to JavaScript via the SRC attribute

In my HTML file I have linked to the JS with: src=”myscript.js?config=true” Can my JS directly read the value of this var like this? alert (config); This does not work, and the FireFox Error Console says “config is not defined”. How do I read the vars passed via the src attribute in the JS file? … Read more

How do I set the src to an iframe with jQuery?

My iFrame looks like this: <iframe id=”iframe” name=”iframe1″ frameborder=”0″ src=””></iframe> And my script looks like this: <script type=”text/javascript”> $(document).ready(function() { $(‘#iframe’).attr(‘src’,http://google.com); }) </script> I’ve also tried putting quotes around the url: <script type=”text/javascript”> $(document).ready(function() { $(‘#iframe’).attr(‘src’,’http://google.com’); }) </script> But neither is working. What am I missing? Answer If you look at the browser’s error console, … Read more

What is the difference between a source folder and a (normal) folder

I’m following this guide: Spring MVC and I realized that I do not know the difference between a source folder (src) and a plain folder. I’m using eclipse, so maybe the difference is only useful in an IDE? Also, I’ve noticed that java classes tend to go in src folders; whilst every other file goes … Read more

Is it possible to change img src attribute using css?

I’m trying to change img src (not the background img src) with css <img id=”btnUp” src=”img/btnUp.png” alt=”btnUp”/> #btnUp{ cursor:pointer; } #btnUp:hover{ src:img/btnUpHover; /* is this possible ? It would be so elegant way.*/ } Answer You can use : content: url(“/_layouts/images/GEARS_AN.GIF”) AttributionSource : Link , Question Author : qadenza , Answer Author : Pranav 웃

javascript check if img src is valid? [duplicate]

This question already has answers here: jQuery/JavaScript to replace broken images (32 answers) Closed 8 years ago. I have something like: document.getElementById(‘MyPicture’).src = ‘attempted.png’; If the client cannot get that resource, I would like to replace it with: document.getElementById(‘MyPicture’).src = ‘error.png’ I know I can put onError=function() in the image tag, but how can I … Read more