Here is a simple JavaScript function that can be used to move a html element to a random direction in page.
click on the code to select it.
//sets a random absolute position to a html element; receives the html element
function moveElmRand(elm){
  elm.style.position ='absolute';
  elm.style.top = Math.floor(Math.random()*90+5)+'%';
  elm.style.left = Math.floor(Math.random()*90+5)+'%';
}
- In the following example the moveElmRand() function is called when the mouse is over the button.
<button id="btn_test">Catch Me</button>
<script>
//sets a random absolute position to a html element; receives the html element
function moveElmRand(elm){
  elm.style.position ='absolute';
  elm.style.top = Math.floor(Math.random()*90+5)+'%';
  elm.style.left = Math.floor(Math.random()*90+5)+'%';
}

//get the #btn_test
var btn_test = document.querySelector('#btn_test');

//register to call moveElmRand() on mouseover event to #btn_test
btn_test.addEventListener('mouseover', function(e){ moveElmRand(e.target);});

//register click to #btn_test
btn_test.addEventListener('click', function(e){ alert('You are Good.');});
</script>
- Demo:
Try to click on this button:

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which tag adds a new line into a paragraph?
<b> <br> <p>
First line ...<br>
Other line...
Which CSS property can be used to add space between letters?
text-size word-spacing letter-spacing
#id {
  letter-spacing: 2px;
}
What JavaScript function can be used to get access to HTML element with a specified ID?
getElementById() getElementsByTagName() createElement()
var elm = document.getElementById("theID");
var content = elm.innerHTML;
alert(content);
Click on the "echo" correct instruction.
echo "CoursesWeb.net" echo "CoursesWeb.net"; echo ""CoursesWeb.net";
echo "Address URL: http://CoursesWeb.net";
Moving html element to a random direction

Last accessed pages

  1. Golf Putt It In (739)
  2. Disable button and Enable it after specified time (5129)
  3. Flash Games - Free online Games (22975)
  4. Move image from an element /tag to another (1637)
  5. Display data from PHP Array, or MySQL in HTML table (12648)

Popular pages this month

  1. Qwop (3219)
  2. Get Attribute (ID, Class, Name, Title, Src) with jQuery (2547)
  3. Get the value of the selected /checked checkboxes in a form (1608)
  4. Insert, Select and Update NULL value in MySQL (1423)
  5. Add, Change, and Remove Attributes with jQuery (1301)