Very simple JavaScript question about document.write function

I am new to javascript as well as jQuery. This is the only code I have on a blank page:

<script type="text/javascript" src="jquery.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function() {

            document.write('Hello World');

        });
    </script>

When I load a page in a browser (using FireFox), the status icon, as well as the icon area of ​​the open tab, display the loaded characters, as if they indicated that the document.write function runs continuously in a loop.

Why is this? I'm just trying to say "as soon as the page is ready to display the string Hello World ONCE." What is wrong here?

ps I noticed that if you pull out the document. Already part of the code is missing a loop. I don't know why this event handler caused this problem.

+3
source share
1 answer

document.write, DOM, . DOM, , $(document).ready() DOM.

append().

<script type="text/javascript">
    $(document).ready(function() {

        $('body').append('Hello World');

    });
</script>
+6

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


All Articles