Set current list item as selected in jQuery
<p>I have a list of items; the number of items in the list is different each time:</p>

<blockquote>
<pre><code>&lt;li id='item1'&gt;number_1&lt;li&gt;
&lt;li id='item2'&gt;number_2&lt;li&gt;
…
&lt;li id='itemn'&gt;number_n&lt;li&gt;
</code></pre>
</blockquote>

<p>When a user choose an item. I want to set the item as selected. 
In my code. I can get the id of each item. my problem is I cannot set the item as selected; for example. if I get item2. I want to the item become as </p>

<blockquote>
<pre><code>&lt;li id='item2' class="selected" &gt;number_2&lt;li&gt;
</code></pre>
  
  <p>Since the id is a variable in mycode. I tried lots of ways to do that in my jquery script. like:</p>

<pre><code>$("#id").addClass('selected'); // doesn't work;
$("li" id).addClass('selected'); // doesn't work;
$("#" id).addClass('selected'); // doesn't work;
$($this. id).addClass('selected'); // doesn't work;
</code></pre>
</blockquote>

<p>I searched on the web, maybe this is too simple probem, I didn't find similar questions and answers. Can anybody please help me out. thank you! </p>
