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

137
Vistas
document.getElementById('#ham') doesn't find the element

Whenever I add an addEventListener, or a toggle in javascript, I get ''can't read **** of null" or ''can't read of undefined". I tried many different ways to solve it, deleting the javascript file and recreating it, putting everything inside an "addEventListener('DOMContentLoaded, ...'), moving the javascript code in html file. Nothing works, I don't know why. I tried all the ways that they say on the internet that work.

const hamn= document.getElementById('#ham')

const navLinks= document.getElementById('#navLink')

function openMenu() {
navLinks.classList.toggle('hidden')
}

hamn.addEventListener('click', openMenu)
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

getElementById already knows you're going to pass an id (hence the ById in the name!), so you need to remove the # from the string passed to it. The # is only used in CSS to express an id selector.

You'd only need the # if, instead of getElementById, you were using querySelector(cssSelectorString) which expects you to pass a valid CSS selector.

const hamn= document.getElementById('ham')
const navLinks= document.getElementById('navLink')

function openMenu() {
    navLinks.classList.toggle('hidden')
}

hamn.addEventListener('click', openMenu)
about 4 years ago · Juan Pablo Isaza Denunciar
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