简体   繁体   中英

JQuery with Flask not triggering when I click a link

I am trying to build a cards game using Flask and I want to achieve that without reloading the page, that's how I stumbled upon JQuery. It's my first project working with JS, HTML and CSS mainly because of the Flask. I followed a few tutorials and I'm trying to get step by step to my result, so I started with a print upon button click, but it doesn't seem to work and I have no idea why. This is my JS file:

   $(function(){

   $('.drawCard').on('click', function(){
      console.log("Draw card");
   });

   $('.playerCard').on('click', function(){
      console.log("Player card");
   });
});

And I want it to trigger whenever this button right here gets clicked:

 <a href="#" class="drawCard"><img class="ml-4 img-responsive" src="/static/cards/back.png" width="250" height="363"></a>
            <div class="pt-4">{% block player_cards %}{% endblock %}</div>
{% for card in player_deck %}
<a href="#"><img class="img-responsive playerCard" src="{{ card }}" width="100" height="145"></a>
{% endfor %}

As you can see I tried changing the class to "href", seen that didn't work so I changed it to "img class". I have no idea what I'm supposed to do so I can link the HTML classes to my JS, as I said, this is my first encounter building something in HTML and JS by myself.

Actually it works. All I had to do was to restart the Flask server...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM