Question

Good day all,

As the question states, I would like to have the page redirect to the url in the <link> once the <title> element of the RSS <item> is clicked.

The code in my JQUERY file looks like so,

JQUERY:

var rssUrl = $("item>link").html();

$("item>title").click(function(){
    $(location).attr("href",rssUrl);
});

HTML:

<p>
    <rss version="2.0">
        <channel>
        <item>
          <title>First Article</title>
          <link>http://www.google.com</link>
        </item>
        <br>
        <item>
          <title>Second Article</title>
          <link>http://www.stackoverflow.com</link>
        </item>
        </channel>
    </rss>
</p>

What's happening with this code, is that when I click the title it doesnt redirect to the desired page. The page just reloads.

I would like it so that clicking the FIRST ARTICLE, will redirect to Google. Clicking the SECOND ARTICLE, will redirect to StackOverflow.

I intend to add more <item>s, so I would like each <title> to have the page redirect to the corresponding <link>.

Any assistance is appreciated.

No correct solution

OTHER TIPS

You can use:

$("item>title").click(function(){
    var url = $(this).next().text();
    window.location.replace(url); // or window.location.href = url
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top