2

I'm using simple rss feed parser example from this topic = Rss Parser Example.

$.get('https://stackoverflow.com/feeds/question/10943544', function (data) {
    $(data).find("entry").each(function () { // or "item" or whatever suits your feed
        var el = $(this);

        console.log("------------------------");
        console.log("title      : " + el.find("title").text());
        console.log("author     : " + el.find("author").text());
        console.log("description: " + el.find("description").text());
    });
});

Its perfect, however I want to show each output log in a specific div, eg:

title log goes in to a <div class="Rss-Title"></div> and so on. So at the end I should have something like this:

<div id="Rss">

<div class="Rss-Title"></div>

<div class="Rss-Author"></div>

<div class="Rss-Description"></div>

</div>

My question: whats a proper way to do something like that?

Community
  • 1
  • 1
Cryptaline
  • 39
  • 7

3 Answers3

2

You should use .html() function

<div id="Rss">

<div class="Rss-Title"></div>

<div class="Rss-Author"></div>

<div class="Rss-Description"></div>

</div>

$.get('http://stackoverflow.com/feeds/question/10943544', function (data) {
 $(data).find("entry").each(function () { // or "item" or whatever suits your feed
    var el = $(this);

    $('#Rss-Title').html(el.find("title").text());
    $('#Rss-Author').html(el.find("author").text());
    $('#Rss-Description').html(el.find("description").text());
 });
});
Ish
  • 2,085
  • 3
  • 21
  • 38
1

Instead of console.log, you select the element and place text inside by using html() (or as alternative text())

$.get('http://stackoverflow.com/feeds/question/10943544', function (data) {
    $(data).find("entry").each(function () { // or "item" or whatever suits your feed
        var el = $(this);
        $('.Rss-Title').html("title      : " + el.find("title").text());
        $('.Rss-Author').html("author     : " + el.find("author").text());
        $('.Rss-Description').html("description: " + el.find("description").text());
    });
});
GreyRoofPigeon
  • 17,833
  • 4
  • 36
  • 59
1

Slightly unclear from the title/question what the issue is, so this answer is for:

Console.log in to a div

The "proper" way to do this would be to change the source that does the console.log

To change the console.log to go to a div instead, you can re-write console.log, eg:

console.log("test1")
window.console.log = function(txt) { 
    //alert(txt)
    $("#log").text($("#log").text() + txt);
}
console.log("test2")
freedomn-m
  • 27,664
  • 8
  • 35
  • 57