Javascript code with 2 classes and issue -
i have 1 issue javascript code of clicking buttons in 1 page.
to have code
var el = document.getelementsbyclassname('a'); (var i=0;i<el.length; i++) { el[i].click(); }
but code clicks 1 button, leaves 1 one unclicked , after clicks 3rd button etc. (it goes 1 click leaves 1 , click other.)
my first problem , second problem that
if run again code clicks clicked buttons. has no point.
therefore checked when button clicked, class affected. , i'm trying code see if working doesnt.
var el = document.getelementsbyclassname('num_button'); var ele = document.getelementsbyclassname('num_clicked'); (var i=0;i<el.length; i++) { if ( ele != 1) { el[i].click(); } }
but not working @ all. still clicks button has been clicked.
any solution??? thanks!
edit 1: here html code before click
<div class="stats_wrapper num_stats_wrapper "> <span class=" num_button num_stats_span sprite_icon"> </span> <span class="count num_count num_popup_button "> 13 </span> </div>
html code after click
<div class="stats_wrapper num_stats_wrapper num_clicked "> <span class=" num_button num_stats_span sprite_icon"> </span> <span class="count num_count num_popup_button "> 14 </span> </div>
i believe issue caused changing button class name, , modifying live collection of nodes.
resolve issue can "transform" nodes array , apply click code:
var el = document.getelementsbyclassname('a'); var arr = array.prototype.slice.call(el); (var i=0; i<arr.length; i++) { arr[i].click(); }
for second issue (if understand correctly) want click buttons has not been clicked before.
var el = document.getelementsbyclassname('num_button'); (var i=0; i<el.length; i++) { var ele = el[i]; if (ele.parentnode.classname.indexof('num_clicked') == -1) { ele.click(); } }
Comments
Post a Comment