Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

392
Vistas
Uncaught TypeError: Cannot set properties of null (setting 'onclick')?

I wrote a very simple html css program and add a javascript in it, here is my program and my javascript in it

(my program : https://github.com/phianh2904/phan-8-web-the-band-tablet-responsive)

my javacript in index.html file

    <script>
    var header = document.getElementById('header');
    var mobileMenu = document.getElementById('mobile-menu');

    mobileMenu.onclick = function() {
        console.log(header.clientHeight);
    }

    const buyBtns = document.querySelectorAll('.js-buy-ticket')
    const modal = document.querySelector('.js-modal')
    const modalclose = document.querySelector('.js-modal-close')
    const modalcontainer = document.querySelector('.js-modal-container')

    // ham hien thi modal mua ve tuc la them class open vao modal
    function showBuyTickets() {
        modal.classList.add('open')
    }

    // ham an modal mua ve them class open vao modal
    function hideBuyTickets() {
        modal.classList.remove('open')
    }


    // lap qua tung the button va nghe hanh vi click
    for (const buyBtn of buyBtns) {
        buyBtn.addEventListener('click', showBuyTickets)
    }

    // nghe hanh vi click vao button close
    modalclose.addEventListener('click', hideBuyTickets)

    //clcik vao khoang khong de dong cac the con lai
    modal.addEventListener('click', hideBuyTickets)

    //click vao ben trong thi khong bi lam sao ca
    modalcontainer.addEventListener('click', function(event) {
        event.stopPropagation()
    })
    </script>

As you can see in my javascript code snippet, it is very simple. I Wrote the code

var header = document.getElementById('header');
var mobileMenu = document.getElementById('mobile-menu');
mobileMenu.onclick = function() {
      console.log(header.clientHeight);
}

to show the clientHeight.

But here is the error I had :

picture about my problem

Uncaught TypeError: Cannot set properties of null (setting 'onclick') at index.html:231:28

As they said in this link Uncaught TypeError: Cannot set property 'onclick' of null

I put the script in the end of the body element, and wrap code in but it did not work. So could you please give me some answer for this problem ? Thank you very much for your time.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda