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 %}
1 Like

Never mind this seem to work!

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