0

I have a condition using jinja, and I want to run a piece of js code when that condition is met.

Here is my code:

M.toast({html: 'I am a toast!', classes: 'rounded'})
{% if condition %}
    run js right here
{% endfor %}

Edit: BTW I am using materializecss toasts. Link: https://materializecss.com/toasts.html

KetZoomer
  • 2,701
  • 3
  • 15
  • 43
  • Same question here: https://stackoverflow.com/questions/41188682/call-javascript-function-in-jinja-for-loop – GitGitBoom Jul 09 '20 at 19:53
  • Mine is a if condition. I can put html in my if condition, so I can put js. I want to know how to execute a js command, without a button in html. The reason I wanted to do this, is because I am using jinja conditions. – KetZoomer Jul 09 '20 at 19:56

1 Answers1

1

I guess you can write your javascript code to run within a script tag that way so that it's executed when the page is loaded:

{% if condition %}
    <script type="text/javascript">
      //js code goes there
    </script>
{% endfor %}
Divarrek
  • 325
  • 3
  • 11