HTML: set id for onclick from list
<p>Apologies if this question has already been asked. I'm new to HTML and I'm not familiar with the words I should use to find help with.</p>

<p>I'm using Flask and HTML to make a website.</p>

<p>My code:</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;h3&gt;Click the result you want to investigate&lt;/h3&gt;
{% for r in results %}
  &lt;p id=r["links"] onclick="myFunction(id)"&gt; {{r["title"]}} ({{r["address_snippet"]}})  &lt;/p&gt;
{% endfor %}

&lt;script&gt;
function myFunction(id) {
    document.getElementById(id).innerHTML = "CLICKED HERE";
}
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>I'm trying to print out a list of names, and etc to the screen. The user will click one name, this name will then be returned to a Python function for further analysis.</p>

<p>As a first attempt, I just want to change the text from the name to "CLICKED HERE". However, regardless of which name I click, only the first entry changes.</p>

<p>I can't figure out how to set the id from the container. Any help would be appreciated!</p>

<p>You need to update your code like this, so you get the actual value from the variable <code>r["links"]</code>, by adding the brackets <code>{{r["links"]}}</code></p>

<pre><code>&lt;p id="{{r["links"]}}" onclick="myFunction('{{r["links"]}}')"
</code></pre>

python html string list flask