Can we remove html tag js event by removing event listener to them | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can we remove html tag js event by removing event listener to them

for eg. <div onclick="myFunc()"> click me </div> once it gets clicked in secod time I want remove this event can I do this by JavaScript removeEventListener method.

26th Nov 2016, 7:11 AM
Sachin Shukla
Sachin Shukla - avatar
2 Answers
+ 4
Simply, you cannot do that. If you want to remove event that does not created by addEventListener. You have to use dom for removing or placing attribute of html. try removeAttribute() method to remove attribute of a tag. If I don' understand your problem, please reply. And explain your problem with an example.
26th Nov 2016, 8:25 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 1
yes there is element.removeEventlstener(event , function) actually there are use of flags too and also you can change the functio but as Aditya said element.remove... does not work always there areconditions for security working and others
26th Nov 2016, 9:39 AM
Sandeep Chatterjee