addClass not working while trying to dynamically change class of a div
<p><a href="http://jsfiddle.net/hdn6e/10/" rel="nofollow">http://jsfiddle.net/hdn6e/10/</a></p>

<p>what is wrong here? Have tried everything at my end but nothing seems to be working</p>

<pre><code>&lt;div class="main"&gt;
    &lt;div class="qty" style="float:left"&gt;1&lt;/div&gt;
    &lt;div class="name" &gt;A&lt;/div&gt;    
&lt;/div&gt;
&lt;div id="main"&gt;
    &lt;div class="qty" style="float:left"&gt;2&lt;/div&gt;
    &lt;div class="name"&gt;B&lt;/div&gt;    
&lt;/div&gt;
&lt;input type="button" id="ADD"&gt;


$('#main').on('click', function(){
        $(this).addClass('selected');
    });
$('.name').on('click', function(){
        $(this).addClass('selected');
    });
$('.qty').on('click', function(){
        $(this).addClass('selected');
    });

$('#ADD').click( function(){
        $(".selected").nearest(".qty").text($(".selected").nearest(".qty").text() +1);
    });
</code></pre>
