Create a link or banner in javascript using another javascript

-1

I wanted to put a banner or link in a certain place on the page using a javascript that would look elsewhere on the same page

type

<script>
função que eu colocaria os links ou banners
</script>

<div>
<script>
local que apareceria os links e/ou banner (não sei se precisaria de script aqui)
</script>
</div>
    
asked by anonymous 09.06.2017 / 18:31

1 answer

1

You will need the js function that adds the element or html you need:

 <script>
    function adicionarLink(){
        document.getElementById("div-inserir-link").innerHTML = "<a href='http://google.com.br'>Google</a>";
    };

    document.addEventListener('DOMContentLoaded', function () {
        adicionarLink();
    }, false);
 </script>

The onload function will only call the addition function, but you can do onlick some element, or any other time.

And your html:

<div id='div-inserir-link'></div>
    
09.06.2017 / 18:50