Zagreb completely. I don't understand why the modal window is called on load, then how should this happen on click?

  • 0
    <body>
        <button id="btmCheckEmpty">Проверить</button>
        <script contenteditable>
            window.onload = function() {
                document.getElementById("btmCheckEmpty").onclick = alert('кнопка нажата');
            }
        </script>
    </body>
    JavaScript Anonymous, Nov 13, 2020

  • 2 Answers
  • 0
    Instead of assigning a function, you call it.



    function showAlert () {
    alert('кнопка нажата');
    }
    window.onload = function() {
    document.getElementById("btmCheckEmpty").onclick = showAlert;
    }
    Anonymous

  • 0
    Or like this:

    <body>
    <button id="btmCheckEmpty">Проверить</button>
    <script contenteditable>
    window.onload = function() {
    document.getElementById("btmCheckEmpty").addEventListener('click',function(){alert('кнопка нажата');});
    }
    </script>
    </body>
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!