jeudi 11 février 2016

jquery not getting data attribute value from html form

I am working on laravel 5.1 and backbone.js. on underscore template i have placed data-id attribute with dynamically generated value. i am trying to get data value but giving undefined error. here is my code.

<div class="col-xs-10 p-r-0 comment-user-detail" >
                                    <span class="user-name"><%- loggedInUserName %></span>
                                          <p class="more" ><%= comment.message %></p><br>
                                            <ul class="comment_inner" data-id="<%- comment.id %>">
                                              <li class="fbcommentlike" ><a href="#">Like</a></li>
                                              <li><a href="">Reply</a></li>
                                              <li><i class="fa fa-thumbs-up"></i>1</li>
                                              <li><span class="comment_date_time"><%= moment(comment.created_time.date , 'YYYY-MM-DD h:m:s').format("DD MMMM") %></span> at <span class="comment_date_time"><%= moment(comment.created_time.date , 'YYYY-MM-DD h:m:s').format("h:m") %></span></li>
                                            </ul>
                                        <% }); %>
                                        </span>
                                        </div>

Here is my jquery code.

console.log $(this).attr('data-id')



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire