Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2004
    Location
    Minneapolis, MN, USA
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

    document.getElementsByTagName("div"); has 0 length

    In my blog, I want to hide the content of posts older than the newest one using a script.

    Code:
    <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.

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Remove the brackets here: window.onload=hideOldPosts();

  • #3
    Regular Coder
    Join Date
    May 2004
    Location
    Minneapolis, MN, USA
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Had a "==" where I needed "=", too. Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •