javascript - Loop through different Button Text .onClick -


i'm trying change button text when clicked.

right have

# script loading button $(document).ready ->   $('.loop_button').click ->     $(this).html('<i class="fa fa-spinner fa-spin"></i> uploading...'); 

so when clicked changes fa-spinner icon , uploading... text.

how can insert 3 or more strings displayed in button text. like:

["uploading...", "still uploading", "this file huge"] 

assuming have time intervals want happen, can time-outs. settimeout function execute callback after specified number of milliseconds. so, example:

timeouts = [] $('.loop_button').click ->    button = $(this)    button.html('<i class="fa fa-spinner fa-spin"></i> uploading...')     # switch label after 10 seconds...    timeouts.push settimeout ( ->       button.html('<i class="fa fa-spinner fa-spin"></i> still uploading')    ), 10000     # switch label again after 30 seconds...    timeouts.push settimeout ( ->       button.html('<i class="fa fa-spinner fa-spin"></i> file huge')    ), 30000 

and when upload finishes, should stop pending timeouts:

cleartimeout timeout timeout in timeouts $(".loop_button").html("start") 

here's fiddle showing in action: http://jsfiddle.net/gwcoffey/6jrfp/1/


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -