Thought I had this in the bag...guess I was wrong:
Expected behavior - page loads, then for each element in the array it updates my innerHTML value using setTimeout
Observed behavior - On my hosting it seems to update the value just one time, then it breaks my css before becoming unresponsive. I threw in an alert to see if it's ever running on jsFiddle and it appears to not be running so there's also that 😰
The markup:
<button type="button" id="ctaButton" class="cta btn btn-lg btn-success pulsate" data-keyboard="true" data-toggle="modal" data-target="#contactUs">Get Started Today</button>
The JS:
$(warmup());
function warmup(){
//sanity check
confirm("working???");
setTimeout(changeCTAtext, 3000);
}
function changeCTAtext(){
var ctaList = [ 'Complementary Quotes', 'Book Your Consultation', 'Get Started Today' ];
var myField = document.getElementById("ctaButton");
while (true){
for (var i = 0; i<ctaList.length, i++;){
setTimeout('myField.innerHTML = ctaList[i];', 1000);
};
};
};
and here is the mandatory fiddle as usually requested.
setTimeout("changeCTAtext()", 3000);should besetTimeout(changeCTAtext, 3000);to prevent EVAL-ing the string.'myField.innerHTML = ctaList[i];'in an anonymous function?