...

View Full Version : document.getElementsByTagName("div"); has 0 length



]|V|[agnus
11-15-2004, 12:28 AM
In my blog, I want to hide the content of posts older than the newest one using a script.



<script type="text/javascript">
<![CDATA[
function hideOldPosts() {
var divs = document.getElementsByTagName("div");
alert(divs.length);
var found = 0;
for(i=0;i<divs.length;i++){
if(divs[i].className.substring(1,4)=="post"){
found++;
if(found>1){divs[i].style.display=="none";}
}
}

}
window.onload=hideOldPosts();
]]>
</script>


It alerts divs.length as 0. :confused:

Willy Duitt
11-15-2004, 12:33 AM
Remove the brackets here: window.onload=hideOldPosts();

]|V|[agnus
11-15-2004, 12:51 AM
Had a "==" where I needed "=", too. Thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum