Mouse Click Button without HTML

Hi all,
I have done the Mouse Click Button assignment without using HTML.

    <script>

    let btn = document.createElement("button");
    btn.innerHTML = "Click here to win new Iphone 12 pro";
    btn.addEventListener("click", function () {
      alert("Oh man, That was just a joke.");
    });
    document.body.appendChild(btn);
    </script>

What do you think about such a solution for it?

Best wishes,
Kacper Pajak

Yup this works if you need to add extra functionality. :slight_smile:

Is it better than that one Ivan shows with using HTML?
Is it good to do so?
is it a bad manner?

Both approaches are good. There’s not much difference as such.

<button onclick="myClickHandler()">mybutton is here</button>

//Works better with html. No sandbox to play in. Lol! This worked in Atom. Not sure why the html can be //left out and proceeded with ? What I have typed is left off and only function //myCliciHandler() {alert(“hello Lorraine!”)} my button is here

function myClickHandler() { alert("hello Lorraine!") } mybutton is here