html - Using Custom Javascript Date Variable with IMG SRC Element -


i trying use custom javascript date variable in img src elements on website having trouble it, code not recognizing utcdate variable.. have decided use moment.js me achieve generating current date (in utc format). purpose of drive (and display) images in gallery live in directory named today's date in yyyymmdd format.

html code:

<script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.7.0/moment.js"></script>  <script type="text/javascript"> $(document).ready(function() {       // set element      $("#date").val( moment().format('yyyymmdd') );       // set variable      var utcdate = moment().format('yyyymmdd');  }); </script>  <div class="gallery" align="center">     <h1>title goes here</h1>      <br />      <div class="thumbnails">         <img onmouseover="preview.src=img1.src" name="img1" src="http://some.website/somedirectory/" + utcdate + "/someotherdirectory/image.png" alt=""/>     </div><br/>      <div class="preview" align="center">         <img name="preview" src="http://some.website/somedirectory/" + utcdate + "/someotherdirectory/image.png" alt=""/>     </div>  </div> 

fiddle answer

 var utcdate = moment().format('yyyymmdd');  $("#my_image").attr("src","http://some.website/somedirectory/" + utcdate + "/someotherdirectory/image.png"); 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -