Simple click event in Node js not working

I have a button on the first page you come to in the app (‘index.html’):

    <div class="container">
		<br />
		<div class="btn-container">
			<button type="submit" class="btn btn-test">test</button> 
		</div>
	</div>

On the same level I have a file called clickController.client.js:

 'use strict';

 (function () {

var test = document.querySelector('.btn-test');

test.addEventListener('click', function(){
    console.log('Congrats! You have reached the clickController!');
 });

})();

When I click the ‘test’ button, nothing appears on my browser’s console, but I get no errors. What am I not doing correctly?

Try:

test.addEventListener('click', function(e){
  e.preventDefault();
  console.log('Congrats! You have reached the clickController!');
});

I changed the data to :slight_smile:‘use strict’;

 (function () {

   var test = document.querySelector('.btn-test');

   test.addEventListener('click', function(e){
  e.preventDefault();
  console.log('Congrats! You have reached the clickController!');
  });

  }); 

Stopped and restarted Node.js server

Refreshed the page

Still nothing

It did however give me a “failed to load… favicon” error which I resolved (went back and added a rel=“shortcut icon” link to the head section of the html page). However, now I am back to absolutely nothing happening when I click the same button.

Do you have your project on GitHub?

yes indeed

So where do you link to your javascript inside index.html?

EDIT: You will also have to set a static folder where the server can fetch files that you link to inside index.html. Also, you are not running your anonymous function inside clickController.client.js

I just did an update to that file. Still, no dice.

See the edit of my previous post.

OK. Thank you very much. Let me go back and work on this some more.