www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Cannot set property 'innerHTML' of null

  1. #1
    Join Date
    Nov 2013
    Posts
    15

    resolved [RESOLVED] Cannot set property 'innerHTML' of null

    So I'm trying to make a image slider but I keep getting the error message that is in title.

    Javascript :
    Code:
    var myPics=['img_1.jpg','img_2.jpg','img_3.jpg'],totalPics=myPics.length,i=0,loopTimer;
    function loop(){
    var imageSlider=document.getElementById('imageSlider');
    if(i > (totalPics-1)){i=0;}
    imageSlider.innerHTML='<img src="../img/'+myPics[i]+'">';
    i++;
    loopTimer=setTimeout('loop()',3000);
    }
    function stopGo(obj){
    var txt=obj.innerHTML;
    if(txt==='Stop'){clearTimeout(loopTimer);obj.innerHTML='Start';}
    else{loop();obj.innerHTML='Stop';}
    }
    window.onload=function(){loop();document.getElementById('ign').onclick=function(){stopGo(this);this.blur();}}
    html :
    HTML Code:
    <head>
    <script type="text/javascript" src="js/slider.js"></script>
    </head>
    
    <body>
         <div class="pageContent">
        	<div class="imageSlider"></div>
            <button id="ign">Start</button>
        </div>
    </body>

  2. #2
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    225
    Try to put your <script> tag to the end of a web document so it looks like this.

    Code:
    <head>
    </head>
    
    <body>
         <div class="pageContent">
        	<div class="imageSlider"></div>
            <button id="ign">Start</button>
        </div>
        <script type="text/javascript" src="js/slider.js"></script>
    </body>
    btw. you should put DOCTYPE declaration at the top of your web document to create pages that conforms to the W3C standards and you're also missing the html tag.

    Oh sorry, didn't read your code carefully enough. Now I cannot delete my post :P
    Last edited by tech_soul8; 01-24-2014 at 10:12 AM.

  3. #3
    Join Date
    Nov 2013
    Posts
    15
    didn't work to move the script to the bottom :/
    I know but stripped the html to make it less unnecessary code.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles