5
I need a function that goes through #paicasas and leaves the background of all children "casa1,casa2...".
I tried to do it but I know it’s far from right.
function apagar(){
for(var i in document.getElementById('paicasas')){
document.getElementById('paicasas')[i].style.backgroundColor = "#FFF";
}
}
HTML
<div id="paicasas">
<div id="casa1" onclick="mudarbg(this)"></div>
<div id="casa2" onclick="mudarbg(this)"></div>
<div id="casa3" onclick="mudarbg(this)"></div>
</br>
<div id="casa4" onclick="mudarbg(this)"></div>
<div id="casa5" onclick="mudarbg(this)"></div>
<div id="casa6" onclick="mudarbg(this)"></div>
</br>
<div id="casa7" onclick="mudarbg(this)"></div>
<div id="casa8" onclick="mudarbg(this)"></div>
<div id="casa9" onclick="mudarbg(this)"></div>
<button type="button" onclick="apagar()">Novo</button>
</div>
Taking advantage, I really need some material that explains about DOM.
On the material of DOM, for being a slightly different subject, it is necessary to open a new question, ok? :)
– Rui Pimentel
What did you expect
for(var i in document.getElementById('paicasas'))
were to? In general, it is not recommended to use "for .. in" to access arrays (or array-Likes), so that even if the children of that element were in indexes the most correct way to iterate on them would be using a common "for" even.– mgibsonbr
And where it is recommended to use for in?
– ropbla9