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. Read Excel file data in PHP - PhpExcelReader (56751)
  2. Insert, Select and Update NULL value in MySQL (26535)
  3. jQuery Drag and Drop Rows between two similar Tables (6882)
  4. Ajax-PHP Chat Script (36546)
  5. JavaScript code and PHP (20369)

Popular pages this month

  1. Read Excel file data in PHP - PhpExcelReader (488)
  2. PhpSpreadsheet - Read, Write Excel and LibreOffice Calc files (388)
  3. Register and show online users and visitors (365)
  4. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (346)
  5. Insert, Select and Update NULL value in MySQL (237)