Article 4XC24 Javascript ES6 and Rails

Javascript ES6 and Rails

by
grail
from LinuxQuestions.org on (#4XC24)
Hoping someone can help me understand if I have made a mistake or not?

I have the following javascript code:
Code:document.addEventListener('DOMContentLoaded', () => {
let link = document.getElementById('be_gone');

if (link) {
link.onclick = () => link.style.display = "none";
}
}, false);When I first arrive on the page associated to the code and click the link it disappears just fine. If I then refresh the page and the link comes back and click it, it once again will disappear.

However, I have another link on the page which links back to the same page:
Code:<a class="btn btn-secondary" href="#">
Yeah <img class="far fa-thumbs-up" src="" />
</a>When I click this link, my disappeared link re-appears but is now not working, ie. when clicked it will no longer disappear.

Would someone be able to tell me if this behaviour is correct or is there a change I can make to the code so it will always work?

Please let me know if any other information is required as I am new to javascript?latest?d=yIl2AUoC8zA latest?i=0Bpf0mHQoKI:0TFPwCA9SQg:F7zBnMy latest?i=0Bpf0mHQoKI:0TFPwCA9SQg:V_sGLiP latest?d=qj6IDK7rITs latest?i=0Bpf0mHQoKI:0TFPwCA9SQg:gIN9vFw0Bpf0mHQoKI
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments