JQuery, getting 'undefined' message when trying to access the ID of a textarea
<p>I'm trying to update the ID of a form element using jquery's attr() function. For debugging purposes.</p>

<p>I seem to be able to assign values to other elements, such as attr('title','test') works just fine. It's only when I want to update the ID.</p>

<p>My entire reason for wanting to update the ID, is that I am building form fields dynamically and need to assign them ID's.</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;

&lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;
   &lt;script&gt;
   function addQuestion(){
   $('#question0Container').clone().appendTo('#questionArea');
   $('#add').attr('id','newid');
   alertText = $('#add').attr('id'); 
   alert("The id is:" + alertText);
   }
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div id="questionArea"&gt;
  &lt;div id="question0Container"&gt;
  &lt;textarea id="question0" name="question0"&gt;&lt;/textarea&gt;&lt;p&gt;Answers&lt;/p&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;a href="#" onClick="addQuestion();" id="add" title="Add a question"&gt;add question&lt;/a&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>
