Display text content of an active element in jQuery slot machine -


i'm using jquery-slotmachine, randomizer. here html:

<div id="machine1">     <span class="option">         <span>example a</span>         <span>example b</span>     </span> </div> <div id="machine2">     <span class="option">         <span>example c</span>         <span>example d</span>     </span> </div> <div id="results">     <span></span> </div> 

here js:

var machine1 = $("#machine1").slotmachine({     active  : 0,     delay   : 500 });  var machine2 = $("#machine2").slotmachine({     active  : 1,     delay   : 500,     direction: 'down' });  function oncomplete(active){     switch(this.element[0].id){         case 'machine1':             $("#machine1result").text(this.active);             break;         case 'machine2':             $("#machine2result").text(this.active);             break;     }  }  $("#randomizebutton").click(function(){      machine1.shuffle(5, oncomplete);      settimeout(function(){         machine2.shuffle(5, oncomplete);     }, 500);  }); 

so i'm trying spit out results in container called "results". know this.active gives me index number of current element, want show text value. inside of want show like, "example b example c".

i've tried using stuff var $results = $('.active').text(); $('#results').html($results); jquery isn't strong suit.

try following:

 $(document).ready(function() {   var machine1 = $("#machine1").slotmachine({     active: 0,     delay: 500   });    var machine2 = $("#machine2").slotmachine({     active: 1,     delay: 500,     direction: "down"   });    var results;    function oncomplete(active) {     switch (this.element[0].id) {       case "machine1":         $("#machine1result").text(this.active);         results[0] = getmachineresult($('#machine1'), this.active);         break;       case "machine2":         $("#machine2result").text(this.active);         results[1] = getmachineresult($('#machine2'), this.active);         break;     }     $("#results").text(results.join(", "));   }    function getmachineresult(i_jqmachine, i_iactive){       return i_jqmachine.find('span.option > span').eq(i_iactive + 1).text();   }    $("#randomizebutton").click(function() {     results = [];     $("#results").css('color', 'white').text("");     machine1.shuffle(5, oncomplete);     settimeout(function() {       machine2.shuffle(5, oncomplete);     }, 500);   }); }); 

i've initialized results array hold results each machine completes. i've added getmachineresult routine retrieve results machine given "active" value. use routine store results in array. concatenated array displayed in #results container.

lastly, cleared results array , results display when click button. css('color', 'white') see results.

i think should it.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -