Javascript examples for DOM Event:onclick
Handle onclick event for child elements
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/* ww w .j a v a 2 s .c o m*/ var childs = document.getElementById('link').children; for (var i = 0; childs[i]; i++) { childs[i].onclick = function () { this.style.color = "#ff0000"; } } } </script> </head> <body> <div id="link"> <p>text1</p> <p>text1</p> <p>text1</p> </div> </body> </html>