title: How to change HTML attributes using Flask and Jinja2 templates?
body: <p>I am using Flask with Jinja2 templates. I have a Jinja2 loop populating a table. I have buttons to collapse/expand a nested table for each row in the outer table.</p>
  <p>The way I’ve approached this is to place the hidden table inside of a Jinja2 if statement. However, I have no way to update the variable that the if statement calls. I couldn’t use JavaScript since it is inside a Jinja2 loop.</p>
  <p>Is there a way to update a variable on a button click inside a Jinja2 loop? Or a way to change HTML attributes (style visibility and hidden)?</p>
  <p>HTML:</p>
  <pre><code>{% for row in table %}
  &lt;tr&gt;
      &lt;td&gt;
          &lt;button&gt;
              &lt;!—- Click button to toggle row.visible —&gt;
          &lt;/button&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  {% if row.visible %}
  &lt;tr&gt;
      &lt;td&gt;
          &lt;table&gt;
              &lt;!—- Hidden table -—&gt;
          &lt;/table&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  {% endif %}
  {% endfor %}
  
  </code></pre>