Doesn't wanna run plugin on dynamically added content
Hi,
I'm trying to use the SlidesJS plugin on a mobile app I'm working on. When I statically have the images in the page, it loads fine. However, I need to have the images loaded dynamically (along with the other data, related to the listing). At the moment I have the following HTML:
- <div id="slides-wrapper"> </div>
Then the following JS, which grabs the JSON and adds in the related HTML:
- $.getJSON("http://www.site.com/cgi-bin/links/ajax_mobi.cgi",{
- action: 'load_link_detailed', t: temp_set,
- ID: $(this).attr('rel')
- }, function(data) {
- console.log(data)
- //$("#detailed_page_holder").html();
- $("#detailed_page_holder #page_title").html(data.Title);
- // now for each image, lets add them to the slides div
- var back = "";
- if (data.Image1_url) {
- back += '<div class="gallery-div"><img src="' + data.Image1_url +'" /></div>';
- }
- if (data.Image2_url) {
- back += '<div class="gallery-div"><img src="' + data.Image2_url +'" /></div>';
- }
- if (data.Image3_url) {
- back += '<div class="gallery-div"><img src="' + data.Image3_url +'" /></div>';
- }
- $('#slides-wrapper').html('<div class="slides">' + back + '</div>'); // empty the div, and add wrapper
- // init slider for images...
- $('#slides').slidesjs({
- play: {
- active: true,
- effect: "slide",
- interval: 5000,
- auto: true,
- swap: true,
- pauseOnHover: false,
- restartDelay: 2500
- }
- });
- });
The HTML seems to get added ok (looking in the "Elements" section of Firebug);
- <div id="slides-wrapper"><div class="slides"><div class="gallery-div"><img src="http://chambresorgslides.ereserveltd.netdna-cdn.com/links/images/6/medium-259886-dsc00480.jpg"></div><div class="gallery-div"><img src="http://chambresorgslides.ereserveltd.netdna-cdn.com/links/images/0/medium-259890-dsc00487.jpg"></div><div class="gallery-div"><img src="http://chambresorgslides.ereserveltd.netdna-cdn.com/links/images/8/medium-259898-dsc00494.jpg"></div></div></div>
..but when the $('#slides').slidesjs() function gets called, nothing is executed.
Do I need to do anything fancy cos the content is loaded AFTER the initial page load?
TIA
Andy