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>
<ul> <li>http://coursesweb.net/html/</li> <li>http://coursesweb.net/css/</li> </ul>
.some_class { display: list-item; }
var obj = { "courses": ["php", "javascript", "ajax"] }; var jsonstr = JSON.stringify(obj); alert(jsonstr); // {"courses":["php","javascript","ajax"]}
$strhtml = '<body><div id="dv1">CoursesWeb.net</div></body>'; $dochtml = new DOMDocument(); $dochtml->loadHTML($strhtml); $elm = $dochtml->getElementById("dv1"); echo $elm->nodeValue; // CoursesWeb.net