Total Amount Of Times A Link Is Clicked
Okay so I have a link that is directed to one website example: Click me! So what I want to chnage the href link after the 10th tim
Solution 1:
You need to preserve the value in a cookie/local storage to retain the value across multiple sessions. You can use a library like jQuery cookie to make the cookie operations easy
Ex:
$(document).ready(function () {
$('a').click(function () {
var count = parseInt($.cookie('link-count'), 10) || 0
count++;
if (count > 10) {
$('a').attr("href", "https://www.yahoo.com");
}
$.cookie('link-count', count)
});
});
Demo: Fiddle - click on the link and refresh the page the counter will retain the value
Solution 2:
Using a cookie you can save the state and later read it and use it.
With jQuery it is very easy to use cookies.
$.cookie("var", "10");
Post a Comment for "Total Amount Of Times A Link Is Clicked"