simar kaur
simar kaur

Reputation: 221

jQuery click not fired

I have this simple html file with little bit of jQuery in it but click event is not triggered here:

I am not getting any error and neither the console.log statement that I expect to print when click event is triggered. Did I miss out on something?

<!doctype html>
 <html>
  <head>
      <title>My WebPage</title>
      <link rel="stylesheet" type="text/css" href="Day.css"/>
      <link rel="stylesheet" type="text/css" href="Night.css"/>
  </head>
    <body>
        <h1> My website </h1>
        <button>Day</button>
        <button>Night</button>
        <script src="jquery.js"/>

       <script>
           (function(){
            console.log('Inside func');
              $('button').click(function() {
              console.log('button was clicked');
              });
            })();
       </script>
    </body>
 </html>

Upvotes: 0

Views: 37

Answers (2)

sleepDrifter
sleepDrifter

Reputation: 591

I would just use the JQuery CDN in the head section.

Here's a demo

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1039438

<script src="jquery.js"/>

should become:

<script src="jquery.js"></script>

You can read more about self-closing script tags here: Why don't self-closing script tags work?

Upvotes: 4

Related Questions