Skip to content

Instantly share code, notes, and snippets.

@benbarnett
Created March 9, 2011 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benbarnett/862066 to your computer and use it in GitHub Desktop.
Save benbarnett/862066 to your computer and use it in GitHub Desktop.
demo of jquery get enhanced
var sillyWords = ["incredible", "awesome", "amazing", "fantastic"];
$('button#start').click(function() {
var button = $(this).attr('disabled', 'disabled');
$.get('endpoint/data.html #target', function(data) {
// do something amazing with the data
if (data) {
// fetch word
var word = sillyWords[Math.floor(Math.random() * sillyWords.length)];
// replace
var output = data.replace(/cool/ig, word);
// write to DOM
$('.target').html(output);
}
button.removeAttr('disabled');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment