SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post I get error: Null

    Hi can you help me on this error

    TypeError: bodycont is null
    here is my code:

    Code:
    
    <!DOCTYPE html>
    
    <html>
      
      <head>
        <meta charset="utf-8"/>
    	
    	<style type="text/css">
    	  .rembull ul{
    	    list-style: none;
    	  }
    	 
    	  ul img{
    	    width: 100px;
    	  }
    	  
    	  #bodycontainer{
    	    background: #555555;
    		width: 100%;
    		height: 100%;
    		position: absolute;
    		border: 1px solid blue;
    		top: 0;
    		left: 0;
    		z-index: 10;
    		opacity: 0.7;
    	    display: none;
    	  }
    	  #pic{
    	    
    	  }
    	  
    	  #zoomout{
    	    position: relative;
    		left:  300px;
    		bottom: 300px;
    		width: 250px;
    		height: 250px;
    		border: 1px solid red;
    		display: none;
    	  }
    	
    	</style>
    	
      </head>
      
       <body>
       
    	    <div class="rembull">
    		   <ul id="pic">
    			   <li><img src="image/pic-1.jpg"/></li>
    			   <li><img src="image/pic-2.jpg"/></li>
    			   <li><img src="image/pic-3.jpg"/></li>
    			   <li><img src="image/pic-4.jpg"/></li>
    		   </ul>
    		<div>
        
    		<div class="bodycontainer"> 
    			 
    	    </div>
    	
    	    <div id="zoomout">
    	    
    	    </div>
    	 
    	 <script>
    	 
    		 var pic, items,zoom;
    	
    		 pic = document.getElementById("pic");
    		 items = pic.getElementsByTagName("li");
    		 console.log(items);
    	     console.log(document.getElementById("pic"));
    		
    	     var i=0;
    		 var itemslen,bodycont;
    			
    	
    		pic.addEventListener("click",function(e){
    			 
    			 if(e.target.tagName === "IMG")
    			    {
    				  bodycont =  document.getElementById("bodycontainer"); 
    				  zoom  =  document.getElementById("zoomout");  
    				  
    				  bodycont.style.display="block";
    				  zoom.style.display="block";
    				  
    				}
    		});
    	
    			
    	    
    		 
    		 
    
    	 </script>
    	 
       </body>
    </html>

  2. #2
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whooo...i got it...i use wrong selector instead of using ID i used class


    <div class="bodycontainer">

    </div>
    should be like this

    <div id="bodycontainer">

    </div>
    .... it's working now...


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
  •