Learn free online HTML5, javascript, and jquery Tutorials by Examples

Sunday, 14 September 2014

How to add anchor tags dynamically to a div in Javascript?

-----------------------------------------
<div id="tik">
    <a>link</a>
</div> 

<script>
var mydiv = document.getElementById("tik");
var aTag = document.createElement('a');
aTag.setAttribute('href',"yourlink.htm");
aTag.innerHTML = "link text";
mydiv.appendChild(aTag);
</script>

---------------------------------

No comments:

Post a Comment