javascript - jquery .length- error says not valid property -
this question has answer here:
i'm trying see if there elements inside 1 div, , also, if there more 1 element in div. if so, want things happen. i've gotten errors running script (not valid property) , more of js script doesn't executed if it's below this. so, other moving script down js page, options? logic seems fine, error bothers me.
var firstdiv = $('.firstdiv'); var seconddiv = $('.seconddiv'); if( (seconddiv).html().length > 0 || $(firstdiv).html().length > 1 ){ make stuff happen }
as minusfour mentioned, make sure selectors correct. if jquery object empty, html()
method return null
. there no length
property on null
.
you can see how many elements jquery object wraps using length
property:
$('.seconddiv').length // should greater 0
Comments
Post a Comment