javascript - is it possible to attach the value in html elements like php have -


just increase knowledge, asking question you. think, possible attach value in html elements php.

let brief example. in php.

 <img src="<?php echo $imgsource ?>" title="<?php echo $imgsourcetitle ?>" > 

can same in javascript or jquery.
this.

<img src="javascript:$(this).val(imgsrc)" title="javascript:$(this).val(imgsrctitle)" > 

it's not possible attach values that, because javascript code not parsed php , should executed once dom ready. change dom elements can use jquery inside $(document).ready()function. try this:

$(document).ready(function()  {      $("#my_a").attr("href","http://google.it");      $("#my_a").attr("title", "my_title");  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <a id="my_a">test</a>

note code executed once page loaded, not @ parsing time (like php does).


Popular posts from this blog