Obtain:
// get by ID var aa = document.getElementById ('bo') ; //Get and return a collection according to the element name var bb = document.getElementsByTagName('input');
Change the background color:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Switch background color</title> <script> function changeColor(color) { var obt1 = document.getElementById('bo'); //obt1.bgColor= 'blue'; obt1.bgColor= color; } </script> </head> <body bgcolor="red" id="bo" > <input type="button" onClick="changeColor('yellow')"> </body> </html>