如何使用Javascript更改第三版背景颜色

如何使用Javascript更改第三版背景颜色,javascript,html,css,Javascript,Html,Css,我有5个分区。上面没有ID或类别。我必须改变第三版的背景色。我试着用下面的颜色,请告诉我哪里出了问题 <div>Div sample content</div> <div>Div sample content</div> <div>Div sample content</div> <div>Div sample content</div> <div>Div

我有5个分区。上面没有ID或类别。我必须改变第三版的背景色。我试着用下面的颜色,请告诉我哪里出了问题

 <div>Div sample content</div>
    <div>Div sample content</div>
    <div>Div sample content</div>
    <div>Div sample content</div>
    <div>Div sample content</div>
Div样本内容
Div样本含量
Div样本含量
Div样本含量
Div样本含量
Javascript

    <input type="button" onclick="getValue()" value="Click"/>

function getValue()
        {
            var result = document.getElementsByTagName('div');

    alert(result.length);
            result[4].style.backgroundcolor ="red";
        }

函数getValue()
{
var result=document.getElementsByTagName('div');
警报(结果长度);
结果[4]。style.backgroundcolor=“红色”;
}

尝试在backgroundColor中大写c。

要更改第三个div的颜色,请使用
结果[2]
并在
backgroundColor中大写
c
函数getValue()
{
var result=document.getElementsByTagName('div');
警报(结果长度);
结果[2]。style.backgroundColor=“红色”;
}
Div样本内容
Div样本含量
Div样本含量
Div样本含量
Div样本含量
试试这个:

result[2].style.backgroundColor ="red";
       ^-third            ^-capital