Item 1
  • Item 2

    Set innerHTML to a variable

    So, I have this code as the body of an HTML file ...

    <body> <ol> <li id="x1"> Item 1 </li> <li> Item 2 </li> </ol> <script type="text/javascript"> var ds = "new text"; document.getElementById("x1").innerHTML = ds; </script> </body> 

    But for some reason, the innerHTML line does not change "Item 1" to "new text." Not sure what is wrong here.

    EDIT: I am using Firefox version 10.0.02, no errors occur in the console, and this is the only thing that uses this identifier on the page.

    +4
    source share
    1 answer

    I would suggest that you use jQuery because doing such a task with jquery is peice of cake $ ("# x1"). innerHTML (ds);

    -one
    source

    Source: https://habr.com/ru/post/1398876/


    All Articles