How to pass Jekyll variable in JavaScript function

I need to pass the value of tag variable in filterByTags(). But the following code throws an error saying "tag is not defined."

{% for tag in unique_tags %}
  <button type="button" id="{{ tag }}" onclick="filterByTags(tag)">{{ tag }}</button>
{% endfor %}
2 Likes

Never mind this seem to work!

{% for tag in unique_tags %}
  <button type="button" id="{{ tag }}" onclick="filterByTags('{{ tag }}')">{{ tag }}</button>
{% endfor %}
2 Likes