Tryit Editor v2.3

Edit This Code:
<!DOCTYPE html> <html> <body> <p>Click the button to change the background color of all child elements of body.</p> <button onclick="myFunction()">Try it</button> <h2>I am a h2 element</h2> <div>I am a div element</div> <span>I am a span element</span> <script> function myFunction() { var c = document.body.children; var i; for (i = 0; i < c.length; i++) { c[i].style.backgroundColor = "red"; } } </script> </body> <!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_element_children4 by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 23 Jan 2015 08:28:24 GMT --> </html>
Result:
Try it Yourself - © w3schools.com