Recording user action to an array with Jquery <p>I am trying to make a simple user click action recorder in jquery but am having some trouble. I want the user to click a record button then once clicked record what he clicks on. Then press stop button to stop recording. What I have so far is:</p> <pre><code>var stack = new Array(); var recordmode = false; $('#record').click(function(){ recordmode = true; alert('You are now in record mode'); }); $('#stop').click(function(){ recordmode = false; console.log(stack);//output what's in the array stack = []; //erase the array }); $('#note_markers').click(function(){ if(recordmode){ $('.one_0').click( function(){ stack.push('one_0'); }) $('.one_1').click( function(){ stack.push('one_1') ; }) } }); </code></pre> <p>and later the start and stop buttons.</p> <pre><code>&lt;a id='record'&gt;R&lt;/a&gt; &lt;a id='stop'&gt;stop&lt;/a&gt; &lt;div id="one_notes"&gt; &lt;a class="one_0"&gt;&lt;/a&gt; &lt;a class="one_1"&gt;&lt;/a&gt; &lt;a class="one_2"&gt;&lt;/a&gt; &lt;a class="one_3"&gt;&lt;/a&gt; &lt;/div&gt; </code></pre> <p>Also before stopping and erasing the array..I would like to build a URL in the form of /one_0/one_1/one_0 etc with what was in recorded in the array. (haven't got to that part yet though)</p> <p>What happens is the first click is not recorded and after that it starts putting in two of the same element. I can't figure out why I am getting the current behavior. </p> <p>Any ideas?</p> <p>As a side note is there a way to get the name of ANY clicked element?</p>