0

I wanted to add some code on clicking of a Div element with id "div_click1". For that I added following code to my custom js

document.getElementById("#div_click1").addEventListener('click', function(){    
// code
},false)

I did not see any error because of this code till I had to reinstall wamp.

I tried fixes suggested for similar issues but though they stopped the issue but also made it do nothing when the div was clicked.

Will appreciate any help on the topic. Thanks!!

1 Answers1

1

You have to use the same ID in the function call as you use in the element.

You must not add a hash sign in front of it.

A hash sign indicates an id in selector syntax. The getElementById function gets an element by its ID, not by a selector, so you have to pass it an ID, not a selector.

Quentin
  • 800,325
  • 104
  • 1,079
  • 1,205