Skip to content

Instantly share code, notes, and snippets.

@ahgood
Last active May 10, 2017 06:49
Show Gist options
  • Save ahgood/910f37c61728ed06014908fdab6457e9 to your computer and use it in GitHub Desktop.
Save ahgood/910f37c61728ed06014908fdab6457e9 to your computer and use it in GitHub Desktop.
Get all words from a HTML
var uni_words = [];
var all_words = jQuery('body').text().split(/ |\ /);
jQuery.each(all_words, function(index, item){
if (item.length > 1 && /^[A-Za-z][A-Za-z0-9]*$/.test(item)) {
if(jQuery.inArray(item, uni_words) === -1) {
uni_words.push(item);
}
}
});
console.log(uni_words);
/*
//Get HTML code from file but not DOM
jQuery.ajax({
url: location.href,
success: function(data) {
var uni_words = [];
var all_words = jQuery(data).find('body').text().split(/ |\ /);
jQuery.each(all_words, function(index, item) {
if (item.length > 1 && /^[A-Za-z][A-Za-z0-9]*$/.test(item)) {
if (jQuery.inArray(item, uni_words) === -1) {
uni_words.push(item);
}
}
});
console.log(uni_words);
}
});
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment