Skip to content

Instantly share code, notes, and snippets.

@dongcai
Created August 1, 2018 18:32
Show Gist options
  • Save dongcai/158d9b7ce68cf89def67b4c2a499b707 to your computer and use it in GitHub Desktop.
Save dongcai/158d9b7ce68cf89def67b4c2a499b707 to your computer and use it in GitHub Desktop.

Revisions

  1. dongcai created this gist Aug 1, 2018.
    17 changes: 17 additions & 0 deletions jquery.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    function getRedditFeed() {
    var topic = $('#select-topic').val();
    $.getJSON("https://www.reddit.com/r/" + topic + ".json", function(data) {
    $.each(data.data.children, function(i, item) {
    $('<li><a href="' + item.data.url + '" target="_blank">' + item.data.title + '</a></li>').appendTo("#posts");
    });
    });
    }

    $(document).ready(function() {
    getRedditFeed();

    $('#select-topic').change(function() {
    $('#posts').html(''); // clear posts
    getRedditFeed();
    })
    });