How to I add unique id and title to nivo-slider captions using jQuery?
I've started code to pull information from my xml files and spit them out into a format like nivo-slider.
Only in order for nivo-sliders html captions to work you need to have unique ids for the caption div and for the img title attribute. I know that generally you don't use unique ids, but this is how nivo-slider works.
I need help coming up with a way to create unique ids and titles such as: "htmlcaption1", "htmlcaption2", etc...
Here's the code:
- $(document).ready(function()
- {
- $.get('/design/designsystems/unitedway/unitedway.xml', function(d){
- $(d).find('pic').each(function(){
- var title = $(this).find('title').text();
- var image = $(this).find('image').text();
- var caption = $(this).find('caption').text();
- var thumbnail = $(this).find('thumbnail').text();
- var link = $(this).find('link').text();
- var linkdes = $(this).find('linkdes').text();
-
- var html = '<a href="' + link + '"' + 'rel="prettyPhoto"' + 'title="' + linkdes + '"' + '>' + '<img src="' + image + '"' + 'title="#htmlcaption"' + '/>' + '</a>';
- var caption = '<div id="htmlcaption" class="nivo-html-caption">' + title + '<br><span class="caption">' + caption + '</span></div>';
-
- $('#slider').append($(html));
- $('#slider').after($(caption));
-
- });
- });
- });
Here's a link to the xml:
The xml is formated something like this:
- <images>
- <pic>
- <title>Project Title</title>
- <image>/imagetitle1.jpg</image>
- <caption>image caption</caption>
- <thumbnail>/thumbs/imagetitle1.jpg</thumbnail>
- <link>/imagetitle1.jpg</link>
- <linkdes>image caption</linkdes>
- </pic>
- <pic>
- <title>Project Title</title>
- <image>/imagetitle2.jpg</image>
- <caption>image caption</caption>
- <thumbnail>/thumbs/imagetitle2.jpg</thumbnail>
- <link>/imagetitle1.jpg</link>
- <linkdes>image caption</linkdes>
- </pic>
- </images>
The html is something like this:
- <div id="slider-container">
- <div class="slider-wrapper theme-kristy">
- <div id="slider" class="nivoSlider"></div>
- </div>
- </div>