I have a link on which I have attached an attribute setnumber
.
<a class="link-container" href="page1.html" data-setnumber="100">Link to page 1</a>
I want to get this attribute as soon as the user clicks on the link, then I will use this attribute through JQuery to save some information into the database.
$(document).on('click','.link-container',function(){
var el = $(".link-container").attr("data-setenumber");
alert(el);
});
After that or at the same time, I would let the user go to the requested page (page1.html).
But I never get into the JQuery file. I directly go to page1.html.
Is there a better way to do this with a link? The goal is to fill a mySQL table after the user clicks on the link, then bring the user to page1.html.
2
Answers
Do not use
href
to go to the requested pagepage1.html
. First get value ofdata-setenumber
attribute and then redirect topage1.html
.