mercredi 8 avril 2015

javascript if image does not exist don't load it

I've got a code in javascript that loads an image into a popupwindow. I need to check first if there is an image in the tags src. If exists, add popupContent += '<tr><td><img src="'+mypath+'"/></td></tr>'; else do nothing



var mypath = "whatever here but loaded on an ajax get call after hitting a button";
var popupContent = '<table>';
popupContent += '<tr><td>Other fields</td></tr>';
popupContent += '<tr><td><img src="'+mypath+'"/></td></tr>';
popupContent += '</table>';

Aucun commentaire:

Enregistrer un commentaire