Last active
May 10, 2017 06:49
-
-
Save ahgood/910f37c61728ed06014908fdab6457e9 to your computer and use it in GitHub Desktop.
Get all words from a HTML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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