I wrote a small script to load pages with ajax. All links that have the ajax-pls
- class, should be selected.
After I add the eventlistener I remove the class, because I need to parse the included html every time.... right?
(function() {
function addEvent(element, evnt, funct){
if (element.attachEvent)
return element.attachEvent('on'+evnt, funct);
else
return element.addEventListener(evnt, funct, false);
}
var link_click = function (e) {
e.preventDefault();
if (this.getAttribute("href") == 'test1.html') {
var content = document.getElementById('content');
content.innerHTML = "<a href='test3.html' class='ajax-pls'>Test3</a>";
register_listeners();
} else {
alert(this);
}
};
function register_listeners() {
var atags = document.querySelectorAll('a.ajax-pls');
for (i = 0; i < atags.length; i++) {
addEvent(atags[i], 'click', link_click);
atags[i].classList.remove("ajax-pls");
}
}
register_listeners();
})();
It is just test-code. But do I need to do the trick with the class or could I just call register_listeners() after every include?