jquery - handlebars button id to ajax -


imagine have handlebar template this:

       {{#each this}}            {{username}}            <form method="post" id="form-id-{{tirid}}">               <input type="button" id="btn-id-{{tirid}}">            </form>        {{/each}} 

this 1 loops through data , works great ajax method. use button inside template. can give id above in template. how can target specific button activate ajax post method ? following wont work because not operating in template anymore {{ x }} can not found:

       $('#btn-id-{{tirid}}').on('click', '.mydiv', function(event) {             $.ajax({                  type:'post',                  url: 'and on....         }  

hope have suggestion!

you this:

{{#each this}}     {{username}}     <form method="post" id="form-id-{{tirid}}">        <input type="button" id="btn-id-{{tirid}}" class="js-btn" data-id="{{tirid}}">     </form> {{/each}} 

then listen js-btn , use data property id.

$('.js-btn').on('click', '.mydiv', function(event) {        var id = $(this).data().id;        $.ajax({              type:'post',              url: 'and on....     }  

Comments