2

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()

varhawk5
  • 31
  • 4
  • possible duplicate of [jquery- get different page elements](http://stackoverflow.com/questions/7567181/jquery-get-different-page-elements) or [Load content of a div on another page](http://stackoverflow.com/questions/4101770/load-content-of-a-div-on-another-page) – tckmn Mar 25 '13 at 23:01
  • The jQuery load function may be helpful, but it may not work unless the server you are accessing explicitly allows requests from sites on a different domain. Read about it at http://api.jquery.com/load/ – Elias Zamaria Mar 25 '13 at 23:02

0 Answers0