auto increase with ajax

0

I have a voting system that should autoincrement when clicking on a link, basically the structure is as follows:

<ul>
  <li>Uno <a href="#">0</a></li>
  <li>Dos <a href="#">0</a></li>
  <li>Tres <a href="#">0</a></li>
</ul>

When you press the links with zeros, they have to increase one by one, update and save in the database, the latter I do using AJAX.

Both the names and the links are charged from the database. Ideally, if you click on the 'Two' link, the following will appear:

<ul>
  <li>Uno <a href="#">0</a></li>
  <li>Dos <a href="#">1</a></li>
  <li>Tres <a href="#">0</a></li>
</ul>

Any suggestions on how to autoincrement the values? Thanks

    
asked by Johan Solano Contreras 25.10.2018 в 09:00
source

1 answer

1

Here is an example of how to do it with very simple jQuery.

If you have any questions, tell me.

$('li').on('click',function(){
    var actual = $(this).find('a').text();
    var now = parseInt(actual) + 1;
    $(this).find('a').text(now);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
  <li>Uno <a href="#">0</a></li>
  <li>Dos <a href="#">0</a></li>
  <li>Tres <a href="#">0</a></li>
</ul>
    
answered by 25.10.2018 / 09:14
source