Dynamically removing elements from different div
<p>I have the following code:</p>

<pre><code>&lt;div id='a'&gt;
&lt;/div&gt;
....
....
&lt;div id='b'&gt;
&lt;/div&gt;
</code></pre>

<p>combined the script:</p>

<pre><code>$.ajax({
    type:'POST',
    url:'grouplist.php',
    async:false,
    dataType:'json',
    cache:false,
    success:function(result)
    {
        var $ni=$('#a');
        $.each(result,function(key,value)
        {
            var $button=$('&lt;input&gt;&lt;/input&gt;',{
                'type':'button',
                'id':key,
                'class':'button',
                'value':value
                }).appendTo($ni);
            });
    }});
</code></pre>

<p>This creates buttons in the <code>div</code> with a dynamic id. Now I am dynamically adding elements into <code>div</code> with id b if I click on one of these buttons as follows:</p>

<pre><code>$('#a').on('click','.button',function(){
    $('.hmm').remove();
    var x=$(this).attr('id');
    $.ajax({
        type:'POST',
        url:'groupmsg.php',
        async:false,
        data:'id='+x,
        dataType:'json',
        cache:false,
        success:function(result)
        {
            var $na=$('#groups');
            $.each(result,function(key,value)
            {
                var t_msg=value[0]+":"+value[1]+"\t"+value[2];
                var $p = $('&lt;p&gt;&lt;/p&gt;'{'id':'msg'+key,'class':'.hmm'}).html(t_msg).prependTo($na);
            });
            }
            });});
</code></pre>

<p>I am unable to remove the elements of <code>div#b</code> using <code>$('.hmm').remove();</code>. Can someone help me in this regard?</p>
