0

I am not that much familiar with javascript/jquery. I want to put image path in img src. Is that possible to do that like we do in php or some other i need to use.

  <img src="path of file that will come from javascript/ajax" width="35" height="30" id="profile" class="profile img-circle" name="profile" data-original-title="Steve" alt="Steve">

I know in php it is quite easy.

  <img src="<?php echo $imgpath; ?>" width="35" height="30" id="profile" class="profile img-circle" name="profile" data-original-title="Steve" alt="Steve"></a>

I tried putting the same way we did in php like <script>imgpath</script> but it is not working.

Rocx
  • 2,996
  • 14
  • 60
  • 122
  • 3
    This may be of help. http://stackoverflow.com/questions/1232793/javascript-set-img-src – Stephen C Oct 15 '16 at 18:09
  • Check http://stackoverflow.com/questions/3304014/javascript-variable-inside-string-without-concatenation-like-php – Mohammad Oct 15 '16 at 18:11
  • @StephenC i checked that question but i dont understand the concept/logic. If you can put some light then it would be great. – Rocx Oct 15 '16 at 18:12
  • The examples provided in the answers is just targeting the desired img, then replacing the src with whatever you decide to pass in. – Stephen C Oct 15 '16 at 18:19
  • I am trying to achive the same but it seems like something is not right. pic = "path of image" and $("#profile").attr("src", pic); – Rocx Oct 15 '16 at 18:33

0 Answers0