Reputation:
Hi guys I need fix this problem I have more <a>
attr. and when click on different I’ll get same webpage I think about that and issue is in jQuery code
var socialIcons = $(".social a"),
href = socialIcons.attr("href");
socialIcons.on("click",function(e){
e.preventDefault();
setTimeout(function() {
window.location.href = href;
}, 500);
});
Upvotes: 0
Views: 62
Reputation: 780724
You're setting href
to the attribute of the first element that matches the selector when the page is loaded, not the one that the user has actually clicked on. You need to set the variable in the callback function, and make it related to the clicked element (which is this
in the handler function).
socialIcons.on("click",function(e){
e.preventDefault();
var href = $(this).attr("href");
setTimeout(function() {
window.location.href = href;
}, 500);
});
Upvotes: 2