I have the following code:
<div id='a'>
</div>
....
....
<div id='b'>
</div>
combined the script:
$.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=$('<input></input>',{
'type':'button',
'id':key,
'class':'button',
'value':value
}).appendTo($ni);
});
}});
This creates buttons in the div with a dynamic id. Now I am dynamically adding elements into div with id b if I click on one of these buttons as follows:
$('#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 = $('<p></p>'{'id':'msg'+key,'class':'.hmm'}).html(t_msg).prependTo($na);
});
}
});});
I am unable to remove the elements of div#b using $('.hmm').remove();. Can someone help me in this regard?
There is an error in your code, should be:
No dot (.) should be used when setting class.