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

130
Views
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 answers
Answer question

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 Report
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!