treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Twitter JS Validation

  • is there anything wrong with this code? When i validate my site this code is the only thing with errors...

    <script type=\"text/javascript\">
    $(function(){
    $.getJSON('http://www.twitter.com/status/user_timeline/cbullmedia.json?count=10&callback=?',
    function(data){
    $.each(data, function(index, item){
    $('.twitter').append('<div class=\"tweet\"><p>' + item.text + '</p></div>');
    });
    });
    });
    </script>


    Note - the code does work as its meant to.

    Many Thanks
    Chris
  • <!DOCTYPE html>
    <html>
    <head>
    <script src=\"http://code.jquery.com/jquery-latest.js\"></script>

    <script>
    $(document).ready(function(){
    $.getJSON('http://www.twitter.com/status/user_timeline/cbullmedia.json?count=10&callback=?',
    function(data){
    var tweets = '';
    console.log(data);
    $.each(data, function(index, item){
    tweets += '<div id=\"tweet\"><p>' + item.text + '</p></div>'
    });
    $('#twitter').append(tweets);
    });
    });
    </script>
    <style>div#tweet{ height: 20px; margin: 10px; background: red;}</style>
    </head>
    <body>
    <div id=\"twitter\">
    </div>
    </body>
    </html>


    I just ran this.. works fine... basicly the same thing but less resource dependent

    Question, Did you call jquery before hand?
  • "AlCapone" said:
    is there anything wrong with this code? When i validate my site this code is the only thing with errors...

    <script type=\"text/javascript\">
    $(function(){
    $.getJSON('http://www.twitter.com/status/user_timeline/cbullmedia.json?count=10&callback=?',
    function(data){
    $.each(data, function(index, item){
    $('.twitter').append('<div class=\"tweet\"><p>' + item.text + '</p></div>');
    });
    });
    });
    </script>


    Note - the code does work as its meant to.

    Many Thanks
    Chris


    where are you validating the code? HTML validation, CSS validation or jQuery validation?
  • It was on the w3schools html validation, i didnt think that it didnt validate becuse it was jquery. Is there a way around this?
  • What error is the validator showing?
    I generally put all my javascript in its own file, but I don't recall ever getting an error for anything I have put in the document head, so long as it's wrapped in script tags.