jQuery - Get <p> text by variable ID
<p>Here is my code:</p>

<pre><code>var itemCount = 0;
var addTo = "";

$(".add").click(function(){
    alert($(this).attr('id'));
    var itemClicked = $(this).attr('id');
    var a = parseInt(itemClicked);
    alert($(".price").find('#' + a).text());
    itemCount = itemCount + 1;
  }); 
</code></pre>

<p>and</p>

<pre><code>&lt;div class="col-sm-5 col-md-4 col-sm-2"&gt;
  &lt;div class="thumbnail"&gt;
    &lt;img src="..." alt="..."&gt;
    &lt;div class="caption"&gt;
      &lt;h3 class="item-header" id="1"&gt;iPhone&lt;/h3&gt;
      &lt;p&gt;...&lt;/p&gt;
      &lt;p class="hidden" id="1"&gt;1&lt;/p&gt;
      &lt;p class="price" id="1"&gt;19.95&lt;/p&gt;
      &lt;p&gt;&lt;button class="btn btn-primary add" role="button" id="1"&gt;Add to cart&lt;/button&gt; &lt;a href="#" class="btn btn-default" role="button"&gt;More&lt;/a&gt;&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>What I want to do is write a function takes figures out which button triggered the function, and retrieves the according price to the button. In this case I pressed 1, and I want the price according to Item 1.</p>

<p>When I perform alert(a); then I retrieve the number of 1. So I suppose something is wrong with the following line, just cant figure out what...</p>

<pre><code>alert($(".price").find('#' + a).text());
</code></pre>