Hello,
I am trying to solve this problem using jQuery:
Broadly speaking, I have an xml file of URLs and Titles that I would like to use to build a list of links in this format:
- <p><a href="url1">Title1</a></p>
- <p><a href="url2">Title2</a></p>
and so on ...
The xml looks like this:
- <item n="1">
- <link>http://www.mysite.com/page1</link>
- <title>My Site Page 1</title>
- </item>
and so on.
The function to parse the XML is (post AJAX call):
- function parseSearch (xml) {
- $(xml).find(item).each(function() {
- var link = $(this).find("link").text();
- var title = $(this).find("title").text();
-
- $("#output").append(title);
- $("#output").append(link);
- });
- }
which lumps everything together, title , followed by link for all items in the XML into <div id="output"></div>. So far, so good.
I have tried these without success to format the output:
- $("#output").append(title).wrap("<a><\/a>").attr("href", link);
- $("#output").append(title).wrapInner("<a href=''><\/a>").attr("href", link);
This returns a nested array of anchor tags, which clearly not the desired result.
- $("#output").append(title).wrapInner("<a href="+link+"><\/a>");
I feel I am really close, but can't seem to find the missing link. Any
suggestions, pointers to documentation I may have missed, similar examples, etc, that
could help solve the problem are most welcome.
Thanks!
KM