jquery - Parse RSS title into HTML using Javascript -
i trying populate menu on webpage 5 latests topics our site's rss newsfeed using javascript (e.g. jquery - import v. 1.9.1 already), , have been trawling content in here find work, answer suiting problem seems using deprecated scripts.
the rss feed stored on our own server, reading rights should ensured. prefer using javascript of sort , need have titles of e.g. latest x news , links tossed
<li><a href="link article">first news header</a></li> <li><a href="link article">second news header</a></li>
one of answers in here led me jsfiddle:code doesn't seem work? answer in here code gives jquery code have no clue how utilize in html afterwards, might simple guiding me use of this?
i have limited experience using js, appreciate pretty low-tech advice on how things working both in terms of include in .js file , how make appear in html afterwards.
the news feed here:link
thanks!
based on answer found well, put jsfiddle testing purposes. (note i'm using predefined xml string in fiddle since can't access rss feed on domain)
here's code explanation
simple html:
<ul id="feed"> </ul>
javascript:
$(document).ready(function(){ var x=10; // x iteration limit // load xml data. parsed jquery $.get("http://www.flatpanels.dk/rss/nyhed.xml", function(data) { var $xml = $(data); $xml.find("item").each(function(i, val) { // find items in rss , loop // create item object necessary information out of xml var $this = $(this), item = { title: $this.find("title").text(), link: $this.find("link").text(), description: $this.find("description").text(), pubdate: $this.find("pubdate").text(), author: $this.find("author").text(), guid: $this.find("guid").text() }; // replace cdata in item title item.title = item.title.replace("<![cdata[", "").replace("]]>", ""); // #feed selects ul element id feed // , append() appends newly created li element // ul $('#feed').append($('<li><a href="' +item.guid +'">' +item.title +'</a></li>')); return i<(x-1); // (stop after x iterations) }); }); });