Need help with click event

Need help with click event
0.0 0

#1
<body>
   <button onclick="op()">click</button>
   <script>
      function op()
       {
           console.log("i new in javascript");
           
         }

       let mybt = document.getElementById("btn");
       mybt.addEventListener(**'click'** , op());   

     
   </script>

click event is not working data is appear before clicking the button


Simple click event in Node js not working
#2

Firstly, welcome to the forums.

While we are primarily here to help people with their Free Code Camp progress, we are open to people on other paths, too. Some of what you are asking is pretty trivial in the Free Code Camp context, so you might find that if you’re not getting the instruction and material you need in your current studies, the FCC curriculum will really help you get started. At a modest guess I’d say investing a 4-5 hours working through the curriculum here will really pay off. You can find the curriculum at https://freecodecamp.org.

With your current questions, we don’t have enough context to know what you already know or don’t know, so it is impossible to guide you without just telling you the answer (which we won’t do).

Can you post your entire code instead of just a snippet? Also, describe in more detail what you expect your code to do and then tell us what it is doing instead.

Happy coding :slight_smile:

FYI - I moved your question from the other thread, because it was completely unrelated to the other thread’s topic. In the future, start a new topic for each set of related questions you have regarding certain code or a project you are working on. Also, I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.