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

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -