javascript - array with doms turns into variable if only a single exists -



javascript - array with doms turns into variable if only a single exists -

so pretty basic jquery guess.

var counters = $(".move-counter"); (var key in counters) { console.log(counters[key].text()); }

the problem here is, if element class move-counter variable counters wont array, single element, making other .text() fail. can create sure turns array (in way other doing simple .length or of like)?

use jquery's .each() method iterate on elements in collection.

$(".move-counter").each(function() { console.log($(this).text()); });

javascript jquery

Comments

Popular posts from this blog

Using Android Volley to post an array to PHP -

python - How to add an model instance to a django queryset? -

angularjs - No 'Access-Control-Allow-Origin' error from local domain to public API -