Dato Skhiladze
Dato Skhiladze

Reputation: 3

how to hide div from js or jquery

I want to hide div after user is going to click on my website, this script goes for a body. its everywhere on page, but how to hide it when user click, i think it needs jquery or js function, wich will hide the div. I haven't show my div script for some reasons. Thanks dear David.

<Script Language='Javascript'>

$(function(){

$( document ).mousemove(function( event ) {
   var pageCoords = "( " + event.pageX + ", " + event.pageY + " )";
$('div.klk').css({"left":event.pageX-10, "top": event.pageY-10});
});

setTimeout(function() {
     $('.popups').remove();
}, 59000);

$('div.klk').click(function() {$(this).hide(3000); });
 });

</Script>

<div class="klk" >
something goes here... for example like button.
</div>

Upvotes: 0

Views: 79

Answers (2)

Vandervidi
Vandervidi

Reputation: 692

Your code work as is. Dont forget to import jQuery. Just please dont use tags with capital letters like you did in

<Script></Script>

$(function(){

$( document ).mousemove(function( event ) {
   var pageCoords = "( " + event.pageX + ", " + event.pageY + " )";
$('div.klk').css({"left":event.pageX-10, "top": event.pageY-10});
});

setTimeout(function() {
     $('.popups').remove();
}, 59000);

$('div.klk').click(function() {$(this).hide(3000); });
 });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<div class="klk" >
something goes here... for example like button.
</div>

Upvotes: 0

Joy Biswas
Joy Biswas

Reputation: 6527

You need to add position:absolute to the div to move along with cursor;

Check the snippet

$(function(){

  $( document ).mousemove(function( event ) {
   var pageCoords = "( " + event.pageX + ", " + event.pageY + " )";
   //console.log({"left":event.pageX-10, "top": event.pageY-10})
   $('div.klk').css({"left":event.pageX-10, "top": event.pageY-10});
  });

  setTimeout(function() {
     $('.popups').remove();
  }, 59000);

 $('div.klk').click(function() {$(this).hide(3000); });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="klk" style="position:absolute;">
something goes here... for example like button.
</div>

Upvotes: 1

Related Questions