javascript - passing variable value to href argument in anchor tag -


how pass variable value href argument in anchor tag.

<body> <script> var id = "10"; $('a_tag_id').attr('href','http://www.google.com&jobid='+id); </script>   <a id="a_tag_id">something_here</a> </body> 

i want anchor tag after above code executed.

<a href="http://www.google.com&jobid=10">something_here</a> 

but somehow above code not working. there wrong doing?

you have miss # in jquery selector, , insert code inside document.ready make script work when page ready

try this:

<script> $(document).ready(function(){    var id = "10";    $('#a_tag_id').attr('href','http://www.google.com&jobid='+id); }); </script> 

demo


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -