Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
The Code is working fine in console but not when adding into file-Uncaught TypeError: Cannot read properties of null (reading 'style')

Note: Please dont delete this question before looking into - I have seen all the given solution on stackoverflow and tried all but not worked for me please see my code and and see the problem which am getting am getting problem from 3-4 days and looking for it whole day in every site but not any sol worked for me. I am working on Chat application project using socket.io and added one left side navbar on it but its button not working and giving me error but when i am adding that same code into the console its working. help me out and thanks Please Help me!!! and thanks

```
<script type="module" defer>
        let result=function(){

            let sidebar = document.querySelector(".sidebar");
            let closeBtn = document.getElementById("btn");
            let userBtn = document.querySelector(".bx-user");
            let joinRoom = document.querySelector(".joinRoom");
            let logout = document.querySelector(".logout");
    
            function menuBtnChange() {
                if(sidebar.classList.contains("open")){
                    closeBtn?.classList.replace("bx-menu", "bx-menu-alt-right");
                    logout.style.width="250px";
                    joinRoom.style.width="250px";
    
                    var x=document.querySelectorAll(".parahide");
                    for(var i=0;i<x.length;i++){
                        x[i].style.visibility="visible";
                    }
                }
                else {
                    closeBtn.classList.replace("bx-menu-alt-right","bx-menu");
                    logout.style.width="78px";
                    joinRoom.style.width="78px";
    
                    var x=document.querySelectorAll(".parahide");
                    for(var i=0;i<x.length;i++){
                        x[i].style.visibility="hidden";
                    }
                }
            }
            sidebar.classList.toggle("open");
            menuBtnChange();
    
            closeBtn.addEventListener("click", ()=>{
                sidebar.classList.toggle("open");
                menuBtnChange();
            });
    
            userBtn.addEventListener("click", ()=>{
                sidebar.classList.toggle("open");
                menuBtnChange();
            });
    
            joinRoom.addEventListener("click", ()=>{
                sidebar.classList.toggle("open");
                menuBtnChange();
            });
            logout.addEventListener("click", ()=>{
                sidebar.classList.toggle("open");
                menuBtnChange();
            });
        }
    window.onload=result;
    </script>
```
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!