I am trying to make a java script program that takes a list of words and gives you sentences for each word.
So far, you can input a word, and it will link you to "sentence.yourdictionary.com/ + your word". Yourdictionary.com provides a list of sentences based on words. So if you typed in "yo" it would link you to here
I came up with jQuery that gets the first sentence of the list on Yourdictionary.com, which is what I want.
$("ul.example>li").first()
But how can I can I execute this code from my javascript, so it copys the first sentence from yourdictionary, and places it into my html file?
This is my current code, in case you want to see it:
<textarea rows="10" cols="22" onKeydown="if(event.keyCode==13) { getWord(' ') }" id="word"></textarea> <br>
<button onClick='getWord(" ")'>Enter (Spaces)</button><button onClick='getWord("\n")'>Enter (Lines)</button>
<p id="demo"></p>
<script>
var words = [];
var partLink = "http://sentence.yourdictionary.com/";
function getWord(splitter) {
var wordList = $("#word").val();
words = wordList.split(splitter);
for(var i=0; i<words.length; i++) {
makeLink(words[i]);
}
}
function makeLink(word) {
var link = partLink + word;
$("#demo").append("<a href='" + link + "'>" + word +"</a><br/>");
}
</script>
EDIT
To fix this, I used AnyOrigin.com. Then I loaded data.contents into a variable Sitecontents, and turned it into a jQuery object. Then I executed the jquery by doing $("ul.example>li", siteContents).first()