jquery - How to remove a div if only has a one element -


how delete parent div if remove specific div in parent div?

link: http://jsfiddle.net/iurcudan/xzhab/1/ example

 $("button.removed").click(function(){  event.preventdefault();      $(this).parents('.categdetn2').remove(); }); 

when delete div class "categdetn2" remove parent div.

try this.

$("button.removed").click(function(){  event.preventdefault();  if($(this).parents('.categdet').children('.categdetn2').length === 1)      $(this).parents('.categdet').remove();  else      $(this).parents('.categdetn2').remove(); }); 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -