javascript - get content of td element in spotify template -
i working spotify web api , downloaded tutorial on getting users playlist. part works perfectly. i've added track id table , want store in variable when click specific tablerow. spotifys code id part:
<script id="playlist-detail-template" type="text/x-handlebars-template"> <h2>{{name}}</h2> <p>{{{description}}}</p> {{#if images.length}} <img style="background-image:url({{images.0.url}})" class="cover"/> {{/if}} <table id="clickable"> <tr> <th>track</th> <th>artist</th> <th>album</th> <th>track uri</th> </tr> {{#each tracks.items}} <tr > <td>{{track.name}}</td> <td> {{#each track.artists}} {{name}} {{/each}} </td> <td>{{track.album.name}}</td> <td class="trackid">{{track.uri}}</td> </tr> {{/each}} </table> </script> and code extract id:
$( document ).ready(function(){ $('#clickable tr').click(function() { console.log('function executed'); var trackid = $(this).find('.trackid').text(); console.log(trackid); }); }); the extract code works because i've tried on table made myself.but when click absolutely nil happens. doesn't log 'function executed' part. i'm guessing it's because of fact scripted template thing i've never seen before, have no thought prepare it. got ideas?
try this:
$( document ).ready(function(){ $('#clickable tr').each(function() { console.log('function executed'); var trackid = $(this).find('.trackid').html(); console.log(trackid); }); }); javascript jquery html spotify
No comments:
Post a Comment