javascript - jQuery counting spans in a div error -
i'm not sure why code works fine in codepen not on actual site. on site logs 0 always.
var getspans = []; $('#hero span').parent() .each(function(){ getspans.push({ parent: this, spancount: $(this).children('span').length }); }); console.log(getspans.length);
here's codepen: http://codepen.io/spiderian/pen/qwwweq
and why hate javascript. wrapping in doc ready function fixed everything.
$(document).ready(function(){ var getspans = []; $('#canvas #head #hero span').parent() .each(function(){ getspans.push({ parent: this, spancount: $(this).children('span').length }); }); console.log(getspans.length); });
javascript jquery html css arrays
No comments:
Post a Comment