How to write inside a DIV box with javascript

前端 未结 5 393
情深已故
情深已故 2020-12-28 13:34

I\'m making a mini-game where a player attacks a npc and in the center is a white box (div) that I call (log), because when the player damages/attacks the npc, I want to be

相关标签:
5条回答
  • 2020-12-28 13:50

    I would suggest Jquery:

    $("#log").html("Type what you want to be shown to the user");   
    
    0 讨论(0)
  • 2020-12-28 13:55

    If you are using jQuery and you want to add content to the existing contents of the div, you can use .html() within the brackets:

    $("#log").html($('#log').html() + " <br>New content!");
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div id="log">Initial Content</div>

    0 讨论(0)
  • 2020-12-28 14:02

    You can use one of the following methods:

    document.getElementById('log').innerHTML = "text";
    
    document.getElementById('log').innerText = "text";
    
    document.getElementById('log').textContent = "text";
    

    For Jquery:

    $("#log").text("text");
    
    $("#log").html("text");
    
    0 讨论(0)
  • 2020-12-28 14:05

    document.getElementById('log').innerHTML += '<br>Some new content!';
    <div id="log">initial content</div>

    0 讨论(0)
  • 2020-12-28 14:08

    HTML:

    <div id="log"></div>
    

    JS:

    document.getElementById("log").innerHTML="WHATEVER YOU WANT...";
    
    0 讨论(0)
提交回复
热议问题