How do I pass the value of a variable to an specific page element with solely JavaScript?
Let's say I have:
var url="http://www.google.html";
how do I put the URL variable value as the href
value of a specific anchor tag in the page?
I know about str.link()
but how can I use that with a specific element? And can I use link*( to build anch开发者_Python百科ors of images? That didn't seem to work for me. Thanks for the help
For anchor elements:
<a id="myAnchor">link me!</a>
...
<script type="text/javascript">
var url = "http://www.google.html"; // .html is the new .com
var myAnchor = document.getElementById('myAnchor');
myAnchor.href = url;
</script>
精彩评论