I want to change the color of more than one element in a page by clicking on a button. I really thought this would be very but I am having lots of difficulty achieving it. My code as follows changes the first element - and I know this is because i am using document.getElementById but when i change it to document.getElementByClass, it stops working at all. I have tried inline styles and internal styles to no avail. Can someone please please please explain how to do this. I doubt this is impossible. Thanks.
<html>
<head>
<style>
#p1{color:#4d982b;}
</style>
<script type="text/javascript">
function ChangeStyle()
{
document.getElementByClass("p1").style.color="#aaaaaa";
}
</script>
</head>
<body>
<p class="p1">Hello world!</p>
<p class="p1">Hello world!</p>
<input type="button" onclick="ChangeStyle()" value="Change style" />
</body>