Sleeper
Sleeper

Reputation: 65

JQuery onclick code doesn't work

Welcome, I have this code: html:

<script src="loginbox.js"></script>
<div class="menu" id="login">
      <p class="menu">LOG IN</p>
    </div>

js:

  $('#login').on('click', function(){
  document.getElementById('login').hide();
});

The div "login" isn't even clickable

Upvotes: 0

Views: 34

Answers (1)

Vivick
Vivick

Reputation: 4991

Here you go :

$(document).ready(function(){
  $('#login').on('click', function(){
    $(document.getElementById('login')).hide();
  });
});

When you mix pure JS and jQuery, you need to wrap pure JS in a jQueryObject.

PS: I'd swap the $(document.getElementById('login')) for a $("#login") if I were you

Upvotes: 1

Related Questions