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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -