SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2006
    Location
    Massachuttes, USA
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript error in loading a organized list...

    Code:
    <script>
    document.onload = startlinks();
    function startlinks(){
    	var ulobj=document.getElementById('links');
    	var ulist=ulobj.getElementsByTagName("li")
    	for (var x=0; x < ulist.length; x++){
    		var ulistlink=ulist[x].getElementsByTagName("a")[0];
    		savedefaultcontent();
    			ulistlink.onclick = function(){
    			ajaxpage(this.getAttribute("href"));
    			return false;
    		}
    	}
    }		
    </script>
    	</head>
    	<body>
    		<div id="container">
    			Shorten your URL!<br />
    			<div id="main">
    				<ul id='links' class="links">
    					<li><a href="#home">Home</a></li>
    					<li><a href="login.php">Log In</a></li>
    					<li><a href="join.php" rel='data'>Join</a></li>
    					<li><a href="faq.php">FAQ</a></li>
    				</ul>
    				<div id="data">
    				</div>
    			</div>
    		</div>
    	</body>
    </html>
    The issue is the fact that it gives the error "'null' is null or not an object" for these lines:
    Code:
    	var ulobj=document.getElementById('links');
    	var ulist=ulobj.getElementsByTagName("li")
    but as you can see... they exist... any idea how to fix it??

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,014
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)

    list tags

    Maybe
    HTML Code:
    var ulobj=document.getElementById('links');
    var ulist=document.getElementsByTagName("li");
    or
    HTML Code:
    var ulobj=document.getElementById('links');
    var ulist=ulobj.childNodes;


Bookmarks

Posting Permissions

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