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

  • SEARCH
  • Home
  • 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 8852865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:30:27+00:00 2026-06-14T13:30:27+00:00

So first off im fairly new to programming in general and definetley new to

  • 0

So first off im fairly new to programming in general and definetley new to Jinja2. So I am using python with GAE for server side stuff. I am basically getting some data from the web and then parsing through it and displaying it on a web page. To display it correctly I am looping through the different elements using jinja2.

{% for new in news %}
    <div>{{new}}</div>
    <button id = "button"></button>
    <div id ="description"> {{new.description}}</div>
{% endfor %}

The description part is hidden until it is clicked on by the user

$(#button).each(function(){
    $(this).click(function(){
      $(description).toggle();
    });

});

This html is a seperate page that is getting Ajaxed in to my main html page. So basically I dont know how to select each element in the loop to show there individual descriptions. Using the .each() function in Jquery seemed like a good place to start but it wasnt working properly. Is there someway to change the div id to be something different each time it loops through like adding a number to it or something to make each one distinct? Thanks in advance for any help

  • 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-14T13:30:28+00:00Added an answer on June 14, 2026 at 1:30 pm

    I’m doing something similar.

    As you probably know by now, variables set outside of loops in Jinja2 cannot be operated on within the loop. The scope of Jinja2 is a little confusing at times, but I suspect this is deliberate to attempt to keep too much logic out of the template.

    Anyway, I have an id value for each of my news entries.

    {% for entry in news %}
        <div>{{entry.subject}}</div>
        <button id="button_{{entry.id}}" class="clickme">Click Me!</button>
        <div id="description_button_{{entry.id}}">{{entry.description}}</div>
    {% endfor %}
    

    Keep in mind that HTML ids should be unique. For the jQuery, something like:

    $('.button').each(function(){
        $(this).click(function(){
            $('#description_'+$(this).attr('id')).toggle();
        });
    });
    

    What that does is it takes the button’s ID value and appends it to the ID selector of the description div.

    Edit, here’s a working example: http://jsfiddle.net/VQKee/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, i'm fairly new to programming, I've built a few asmx web services
First off, this is my first project using SQLAlchemy, so I'm still fairly new.
first off I am fairly new to php like 3 weeks working with it,
First off, fairly new to JS but getting better :-) This question is similar
First off: I'm fairly new to zk. I try to create a component that
First off, I am fairly new to MVC and jQuery. I apologize if my
First off, I'm fairly new to MVC but have an existing project in MVC3
First off, I'm new to web development. I am fairly comfortable with HTML/CSS, and
I am fairly new to android programming and I'm working off an example from
First off I am fairly new to xcode. I am trying to add multiple

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.