If I have 5 div's like below and am placing innerhtml in some of them how can I find the div id where there is not innerhtml so I may use it. I would like to get the first id that there is no html or text in there so in the code below id="layer2" would be the first empty div.
<script type="text/javascript">
var divs=document.getElementsByTagName("div")
for (var i = 0; i < divs.length; i++) {
if (divs[i].innerHTML==""){
alert(divs[i].id+" is empty")
}
}
</script>
Wait... what? Did Atari die? Oh, man... and I only just updated my avatar
seriously, though - atari seems to be kicking (twitching?) still, and you can even get the classics for mobile and iPad (please don't take this to mean that I knew this before this afternoon). You should check it out - maybe some bits of your code are still rumbling around out there...
Thanks for the code. One question I have is what if I just want to loop through only the div that start "layer". I have another div on the page but it doesn't start with layer. The only layer ones I have is the ones I posted.
<script type="text/javascript">
var divs=document.getElementsByTagName("div")
for (var i = 0; i < divs.length; i++) {
if (divs[i].innerHTML=="" && divs[i].id.match("layer")){
alert(divs[i].id+" is empty")
}
}
</script>