javascript getelementsbyclassname

getElementsByClassName() method grabs all items with the class name into an array.

<STYLE type="text/css">
.n td{border:1px solid #9FA4FF;}
.r td{border:2px solid red;}
.s td{border:1px solid #9FA4FF;}
</STYLE>
<script language="javascript">
function change()
{
var arr=document.getElementsByClassName("n");
for (var i=0;i<arr.length;i++)
{
arr[i].className="r";
}
}
</script>
<input name="change" type=button onclick="change()" value="Change" style="font-size:18px">
<br><br>
<table border=0>
<tr class="n"><td>Bangalore, India</td></tr>
<tr class="s"><td>New York, USA</td></tr>
<tr class="n"><td>Mombay, India</td></tr>
<tr class="s"><td>San Francisco, USA</td></tr>
<tr class="n"><td>New Delhi, India</td></tr>
<tr class="s"><td>Washington DC, USA</td></tr>
</table>



Bangalore, India
New York, USA
Mombay, India
San Francisco, USA
New Delhi, India
Washington DC, USA