1

I tried to create pop ups using for-loop, but does not work. Why?

http://jsfiddle.net/edgardaraujo/Rud3G/2/

I thank you all for the help.

content html

<div data-role="page" id="page1">
    <div data-role="content">
        <div id="output"></div>
    </div>
    <!-- /content -->
</div>


content jquery

var array = new Array();

array[0] = "link-image-1";
array[1] = "link-image-2";
array[2] = "link-image-3";
var len = Object.keys(array).length;

for (i = 0; i < len; i++) {

    var popup = array[i];

    $('#output').css({'font-weight': 'bold'}).append('<a href="#' + popup + '" data-rel="popup" data-position-to="window" data-transition="fade"><img class="popphoto" src="' + popup + '" alt="photo, test" style="width:30%"></a>');

    var arrayPhotos = $('<div data-role="popup" id="' + popup + '" data-overlay-theme="a" data-theme="d" data-corners="false"></div>');

    arrayPhotos.append('<a href="#" data-rel="back" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>   <img class="popphoto" src="' + popup + '" style="max-height:512px;" alt="photo, test">');

}
3

1 Answer 1

3

Upadate

When you create [data-role=popup] dynamically, you need to enhance its markup by using .trigger('create').

Demo


You have a mistake in href of the link to popup. You have used variable popup which holds image links instead of using the count variable i.

href="#popup' + i + '"

Here

$('#output').css({ 'font-weight': 'bold'}).append('<a href="#popup' + i + '" data-rel="popup" data-position-to="window" data-transition="fade"><img class="popphoto" src="' + popup + '" alt="photo, test" style="width:30%"></a>');

And

var arrayPhotos = $('<div data-role="popup" id="popup' + i +'" data-overlay-theme="a" data-theme="d" data-corners="false"></div>');
Sign up to request clarification or add additional context in comments.

5 Comments

The for-loop is not working with the array containing the image links. You associated with the links that are in html. Here is my problem with the for-loop. jsfiddle.net/edgardaraujo/Rud3G/2
I examined your code and it unfortunately did not help me, but thank you.
@Edgard check this and let me know if you need further help jsfiddle.net/Palestinian/UbnVh
great alternative, congratulations. But I could not understand what the error in the for-loop I did? Could you clarify?
@Edgard the problem isn't in the loop, it's the way you appended the items. In the demo I merged popup divs with their images and then used create to enhance their markup.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.