Tricky Button Moving Away when Mouseover in Javascript? [closed]

This is probably what you are looking for:

$(function() {
  $("button").on({
    mouseover: function() {
      $(this).css({
        left: (Math.random() * 200) + "px",
        top: (Math.random() * 200) + "px",
      });
    }
  });
});
button {
  position: absolute;
  top: 10px;
  left: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button>button</button>

http://jsfiddle.net/9CDtE/4/

Leave a Comment