0

I can upload a picture of the problem if you need one, but I need the last item to look like the rest. I read an rss feed and grab the first title, then populate it in the list. I try to format it like the rest, but it is not working. Here is my function:

<script type="text/javascript">

jQuery(function() {

    jQuery.getFeed({
        url: 'xml/rss-21.xml',
        success: function(feed) {

            var html = '';

            for(var i = 0; i < 1; i++) {

                var item = feed.items[i];


                html += '<li data-theme="c">'
                + '<a href="#page1" data-transition="slide">'
                + item.link
                + '">'
                + item.title
                + '</a>'
                + '</li>';
            }

            jQuery('#result').append(html);
        }    
    });
});

</script>

I need it to formatted like:

<li data-theme="c">
                    <a href="http://www.tristateis.com" data-transition="slide">
                        Win a Free Digital Pocket Memo
                    </a>
                </li>

Thank you for your help.

7
  • Can you show us what you're getting ? Commented Aug 9, 2012 at 19:16
  • postimage.org/image/y0nyv4tin Commented Aug 9, 2012 at 19:23
  • I'm at work so i can't see it because of the network restrictions, can you just add the code of what you're getting ? Commented Aug 9, 2012 at 19:30
  • Hey Isaac I got it to format correctly, I was leaving out some css. However it is not working in chrome, but it is working in safari. Any suggestions? Commented Aug 9, 2012 at 19:48
  • What happens in safari that doesn't in chrome ? Commented Aug 9, 2012 at 19:53

3 Answers 3

1

Looks like you're not actually making a link here, the href should be item.link (assuming that's the correct value)

html += '<li data-theme="c">'
        + '<a href="' + item.link +'" data-transition="slide">'
        + item.title
        + '</a>'
        + '</li>';
Sign up to request clarification or add additional context in comments.

3 Comments

Your right, I just need the title to be displayed not the link. I forgot to take that out in my original post. I copy your text above but I still does not look like the rest of the elements in my list. Here is what it looks like: postimage.org/image/y0nyv4tin
in that case it looks like there's probably some class missing that the others have. The html it produces is valid. You can right click on one of the other links and choose inspect element in chrome and it will show all the styles / properties that the tag has
Thank you! I inspected the element and found out what I needed!
1

The problem seems to be on when you're appending to html :

html += '<li data-theme="c">'
            + '<a href="#page1" data-transition="slide">'
            + item.link
            +" "               
            + item.title
            + '</a>'
            + '</li>';

Also what you can do to get more control than just formatting a string is to do this:

var li = $('<li></li>',{
   'data-theme' : 'c',
});

var link = $('<a></a>',{
    href : item.link
    text : item.title,
    'data-transition' : 'slide'
});

And then just li.append(a); that way it's easier to edit and it's also a better practice

Comments

1
html += '<li data-theme="c">'
+ '<a href="#page1" data-transition="slide">'
+ item.link
+ '">' // problem here
+ item.title
+ '</a>'
+ '</li>';

should be

html += '<li data-theme="c">'
+ '<a href="#page1" data-transition="slide">'
+ item.link
+ item.title
+ '</a>'
+ '</li>';

EDIT:

you need to put the link in the right place:

html += '<li data-theme="c">'
+ '<a data-transition="slide" href="'
+ item.link + '" >'
+ item.title
+ '</a>'
+ '</li>';

3 Comments

Thanks for the solutions, but it is still not working correctly, tried both solutions. The text is in the ul,but still not formatted correctly.
you should probably remove the first href="#page1" then
I used your edit, but it looks the same. I do not need item.link, I can just use #page1. Can I use the theme in my jQuery Function?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.