Setting a cookie based on the name of the link that is clicked.
- by Ozaki
TLDR When clicking on a link I want to assign a cookie with a name of instrument and a value of the text on the link clicked.
Using Jquery.1.4.2.min.js, Jquery.cookie.1.0.js
I am trying to create a cookie when a link is clicked (will always link to "page.html").
name of instrument
value of the TEXT
So far I am trying to use:
Link1:
<a href="page.html">link1</a>
Link2:
<a href="page.html">link2</a>
Script:
$('a[href=page.html]').click(function()
{
var name = 'instrument';
var value = $(this).text();
$.cookie(name, value, { expires: 365 });
});
When I click the link it just loads the link and no cookie is set.
Debugging with firebug, firecookie, firequery. No cookie for instrument or anything along the lines is found. Onload I'll hit the
"<a href="page.html">projects</a>" but not the
"$.cookie(name, value, { expires: 365 });" at all.