Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8401623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:51:28+00:00 2026-06-09T21:51:28+00:00

I desire to use a variable i that is incremented in a for loop

  • 0

I desire to use a variable i that is incremented in a for loop to create unique id’s in div’s in a mako template.

var i=0;
    % for p in row.photos: 
    %if not p.PRIVATE:              
    /* setup div's for photo containers*/

    $('#photos').append("<div id='+i+' class='thumbnailimage'></div>"); 
    $('#+i+').append("<div id='+i+container' class='thumb_container'></div>");  
    $('#+i+container').append("<div id='+i+thumb' class='large_thumb'></div>");
    $('#+i+thumb').append("<div class='large_thumb_border'></div>");
    $('#+i+thumb').append("<div class='large_thumb_shine'></div>");

    /*insert the image*/
    $(document.createElement("img")).attr({ "src": "${tg.url('photo/%s/%s' % (p.PHOTOINDEX))}" }).appendTo('#+i+'thumb'');

    i++;


    %endif
% endfor

Result hoping for in the html when the javascript is run:

<div id='photos'>
    <div id='1'class='thumbnailimage'>
        <div id='1container' class='thumb_container'> 

etc.
Instead I get:

<div id='photos'>
    <div id='+1+' class...>
    </div>
</div><!--end photos-->        

Any suggestions?

Following the suggestions below, I changed the code to

$('#photos').append("<div id="'photo'+i+" class='thumbnailimage'></div>"); 
$("#'photo'+i+").append("<div id="'container'+i+" class='thumb_container'></div>");  
$("#'container'+i+").append("<div id="'thumb'+i+" class='large_thumb'></div>");
$("#'thumb'+i+").append("<div class='large_thumb_border'></div>");
$("#'thumb'+i+").append("<div class='large_thumb_shine'></div>");

Now I get an error message:
SyntaxError: missing ) after argument list
[Break On This Error]

$('#photos').append("<div id="photo+i+" class='thumbnailimage'></div>");

with arrow on the p in photo

FINALLY!!
I ended up having to define the whole variable outside of the jQuery command as it kept having problems with the + sign in the jquery href. I used the following code to obtain the desired results.

    var i=0;

    % for p in row.photos:
     var photo='photo'+i;
     var photoId="#"+photo;
     var container='container'+i;
     var containerId="#"+container;
     var thumb='thumb'+i;
     var thumbId="#"+thumb;
       $('#photos').append("<div id="+photo+" class='thumbnailimage'></div>"); 
       $(photoId).append("<div id="+container+" class='thumb_container'></div>");  
       $(containerId).append("<div id="+thumb+" class='large_thumb'></div>");
       $(thumbId).append("<div class='large_thumb_border'></div>");   
       $(thumbId).append("<div class='large_thumb_shine'></div>");
       $(document.createElement("img")).attr({ "src": "${tg.url('photo/%s/%s' % (row.GISNUM, p.PHOTOINDEX))}" }).prependTo(thumbId);
% endfor
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:51:30+00:00Added an answer on June 9, 2026 at 9:51 pm

    Change this:

    $('#photos').append("<div id='+i+' class='thumbnailimage'></div>"); 
    

    to:

    $('#photos').append("<div id='"+i+"' class='thumbnailimage'></div>"); 
    

    Please note that if the doctype of the page is not HTML5, IDs must begin with a letter.


    $('#photos').append("<div id='"+i+"' class='thumbnailimage'></div>"); 
    $('#'+i).append("<div id='"+i+"container' class='thumb_container'></div>");  
    $('#'+i+'container').append("<div id='"+i+"thumb' class='large_thumb'></div>");
    $('#'+i+'thumb').append("<div class='large_thumb_border'></div>");
    $('#'+i+'thumb').append("<div class='large_thumb_shine'></div>");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am generally not one to engage in subjective arguments over matters like variable
I have a base User form that I am subclassing for each use case,
Possible Duplicate: Create categorical variable in R based on range Given a range and
I have a containing div that is constrained in its height and width. It
Would you expect this to work or not? (it seems you can't use XPath
I am trying to use an if statement to determine if a certain variable
I am developing a censored dependent variable for use in survival analysis. My goal
A question mostly for fun/curiosity: how to write a for loop in C++ that
Hello I would like to use preg_match in PHP to parse the Desired text
I can usually get the behavior I desire by just randomly trying different permutations

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.