javascript - jQuery .length or .size -


i've got function per below:

$(".selecteditems").on('click', '.deleteitem', function (event) {     $(this).parent().remove();     if ($(this).parent('.selecteditems').children().length === 0) {        alert('hello');    }  }); 

in conjunction following html:

<div class="selecteditems">     <div class="item">     </div>     <div class="item">     </div> </div> <div class="selecteditems">        <div class="item">       </div>       <div class="item">       </div> </div> 

the problem size showing 0 regardless , if statement keeps on triggering, been looking @ code while.. im not sure can problem.

you can find link jsfiddle here: http://jsfiddle.net/kmcbride/upggq/6/

as mentioned in comments, have removed element , therefore $(this).parent() no longer refers anything.

try storing parent first:

var $parent = $(this).parent(), $selitem = $(this).parents(".selecteditems"); $parent.remove(); if( $selitem.children().length === 0) {     alert("hello!"); } 

updated fiddle


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -