display var Javascript in div html

2

The code

<section class="content">
    <span></span>
    <span></span>
    <script type="text/javascript" src="../js/purl.js"></script>
    <script>
        var vars = geturlvar()['Nome'];//traz embalagem.html se colocar um alert!
    </script>

    <img src="../images/aguarde.gif" id="image">
    <div id="url" w3-include-html=vars></div>       

</section>

I need to get the value that is in vars (which is package.html) and put it inside the <div id="url" w3-include-html=vars></div>

How do I do this?

    
asked by anonymous 25.05.2017 / 20:07

3 answers

1

Thank you all for the help, but I have decided to change the method of including the page packaging.html inside container.html by:

<script type="text/javascript" src="../js/purl.js"></script>
<script>
    var vars = geturlvar()['Nome'];
    $(function () {
        $("#includedContent").load(vars);
    });
</script> 

and no body is:

 <div id="includedContent"></div>
    
25.05.2017 / 21:56
2

You are trying to put the value in the div before it is created. Just put your code inside window.onload , so that it runs after the screen loads

window.onload = function () {
   var vars = "url_de_teste";
   document.getElementById('url').innerHTML = vars;
}
<div id="url"></div>
    
25.05.2017 / 20:32
1

Try this:

<section class="content">
    <span></span>
    <span></span>
    <script type="text/javascript" src="../js/purl.js"></script>


    <img src="../images/aguarde.gif" id="image">
    <div id="url" w3-include-html=vars></div>     

    <script>
        var vars = geturlvar()['Nome'];
        document.getElementById("url").innerHTML = vars;
    </script>  

</section>
    
25.05.2017 / 20:32