Hello i'm recently decided to move my ajax calls from the html elements into my external javaScript file. It works by a function getting executed whenever the client clicks on the page. That function determine which element was clicked on the page and proceeds to get the href attribute if the element is a link('a'). This works really well unless there's another element on top of the link. For example:
<a id="home" href="./"><div id="homeicon"></div></a>
So I was wondering how I could do to make the js detect ALL the elements it has clicked on(the whole stack of elements) and then get the link element('a') that is the highest up in the stack. However here's my current function without the click eventListener.
function linkHandler(e) {
var e = window.e || e;
// Makes sure the element clicked is a link
if(e.target.tagName !== 'A' || useAjax == false){
return false; // Exits if element isn't a link
}
// Makes sure to not use ajax when the middle mouse button and right is clicked
if(e.button == 1 || e.button == 2){
return false; // Exit the click wasn't left click
}
// Prevent regular page request
e.preventDefault(); // Disables the default behaviour request behaviour
// AJAX CALL
}
Another method of doing this would be to set eventListener to every damn link element with a loop obviously and then run a function that refresh the eventListeners after every ajax call.
I just have to say that I will not be using any kind of framework but a jquery answer might be helpfull to people with a simular problem.
I am honestly lost and would appreciate some help on this topic, Thanks.