Using variables in JQuery
<p>I have the following code:</p>

<pre><code>$("#tag-add-button").click(function () {
    var text = $("#tagadd").val();
    var tagcounter=0;
    $("#set-tags").append("&lt;%= render 'tag' %&gt;");
    $("#tag"tagcounter).val(text);
    $("#tagadd").val("");
    tagcounter=tagcounter+1;
});
</code></pre>

<p>Clearly its wrong, but here is what I'm trying to accomplish:</p>

<p>Someone clicks the tag-add-button, the text from tagadd is stored in the "text" var.</p>

<p>The variable tagcounter is set to 0</p>

<p>An input is rendered (within the set-tags div) containing an id such as "tag0", "tag1" etc.</p>

<p>The input ("tag0" etc.) then receives the value from the "text" var. </p>

<p>The original input box "tagadd" is then replaced with nothing ("").</p>

<p>Lastly the tagcounter variable increases by 1.</p>

<p>How can I make this work?</p>
