0

In my project I've binding events to element by calling SMSLiTe() function. I noticed the function gets unbind if a user via the console removes,change element id or class.

Upon trying addEventListener(event,function), if the user via the console removes, change element id or class. I noticed the the event still bind to the element in a fact that it still works.

Can someone explain to me what is happening between the two. here is my code.

HTML:

<span id="c1">click 1</span><br>
<span id="c2">click 2</span><br>
<span id="c3">click 4</span>

JS

//bind events to an element
function SMSLiTe(e,elem,f){
 jQuery(document).on(e,elem,f);
}
$(document).ready(function(){
    //SMSLiTe('click','#c1',function(e){
    //console.log('working');
    //});
    var a  = document.getElementById('c1');
    a.addEventListener('click',function(){ 
        console.log('working...');
    });
});
lernyoung
  • 223
  • 1
  • 2
  • 10
  • What is SMSLiTe()? An API from SMSLite Group...I couldn't find such a thing... – zer00ne Nov 17 '17 at 12:02
  • .I see it looks like a normal function wrapping around a jQuery `.on()` method. Anyways, both methods need to invoke a specific method to remove event listener/handler methods. `removeListener()` and `.off()` – zer00ne Nov 17 '17 at 12:08

0 Answers0