<html> <head> <style> .green { background-color: lime; } </style> </head> <body> <div id="foo">The background of this div should be green.</div> <script> document.getElementById('foo').id = 'goo'; document.getElementById('goo').className = 'green'; </script> </body> </html>