jquery - Javascript: Cannot read property 'style' of null on Else -


the error message: cannot read property 'style' of null shows on first statement of "else" statement. not sure going wrong. thoughts?

$(document).ready(function () {     var foursquareapi = {         clientid: "client_id",         clientsecret: "client_secret",         redirecturl: "http://almontas.github.io/foursquarejax/"     }      if (access_token === 0) {          document.getelementbyid('dashboardprofile').style.display == 'none';         document.getelementbyid('dashboardinfo').style.display == 'none';          $('.connect').click(function () {              var url = "https://foursquare.com/oauth2/access_token";             url += "?client_id=" + foursquareapi.clientid;             url += "&response_type=token";             url += "&redirect_uri=" + foursquareapi.redirecturl;             window.location = url;          });     } else {         document.getelementbyid('dashboardprofile').style.display == 'block'; //this lines gives error message.          document.getelementbyid('dashboardinfo').style.display == 'block';     } 

here of html in question. .dashboardprofile , .dashboardinfo seem in place mentioned comments.

<body>         <div class="container">           <div class="header">             <div class="logo"><img src = "images/foursquare-logo.png">              </div>           </div>              <div class="dashboard-container">               <div class="dashboardconnect">                 <div class="connect"><p> sign in </p>                 </div>             </div>                  <div class="dashboardprofile">                     <p>user information , picture</p>                      </div>                  <div class="dashboardinfo">                     <p>check ins </p>                        <div class="indicator checkin"> # </div>                      <p>countries</p>                        <div class="indicator country"> # </div>                      <p>cities</p>                        <div class="indicator city"> # </div>                   </div>             </div>         </div><!--container-fluid--> 

you don't have element id dashboardprofile, have element class dashboardprofile.

so do:

document.getelementsbyclassname('dashboardprofile')[0].style.display = "none" 

same goes other document.getelementbyid, don't have elements ids in html.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -