Use find() to achieve this. Since closest() will intersect through its ancestors in the DOM tree, and not in its divisions.
$('.demo-select').find('.test').remove(); //OR simply $(this).find('.test').remove()
Update
For multiple items, use $(this)
var selected = $('.demo-select'); selected.click(function() { $(this).toggleClass('selected'); if ($(this).hasClass('selected')) { //HERE $(this) //alert(1); $(this).append('<p class="test">check</p>'); } else { //alert(2); $('this').find('.test').remove(); //HERE $(this) and find() } });
source share