 <p>Change this</p> <pre><code>onclick= "SaveData();" </code></pre> <p>to </p> <pre><code>onclick= "SaveData(this);" </code></pre> <p>Then change the <code>saveData</code> function to</p> <pre><code>function SaveData(elem) { localStorage["LessonID"] = $(elem).attr('LessonID'); localStorage["SubjectName"] = $(elem).find('.lesson_subject').text(); } </code></pre> <p>Or even better, you can use <code>$.on</code> like @James Allardice showed in his answer.</p>