Here is a simple JavaScript function that can be used to move a html element to a random direction in page.
//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)+'%'; }
<h4>Example auto-moving html element</h4> <p>Try to click on the following button.</p> <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 mouseenter event to #btn_test btn_test.addEventListener('mouseenter', function(e){ moveElmRand(e.target);}); //register click to #btn_test btn_test.addEventListener('click', function(e){ alert('You are Good.');}); </script>
<meta name="description" content="70-160 characters that describes the content of the page" />
#some_id { clear: both; }
var divs = document.getElementsByTagName("div"); var nr_divs = divs.length; alert(nr_divs);
$arr =[7, 8, "abc", 10); $nri = count($arr); echo $nri; // 4