javascript - jQuery selector problems -
i have tabs' info rendered handlebars , here html:
<ul class="nav nav-tabs" id="tabsid"> <script id="tabs-template" type="text/x-handlebars-template"> {{#each tabs}} <li data-tab-content={{id}}><a href="#">{{name}}</a></li> {{/each}} </script> </ul> <div id="tabscontentid"> <script id="tabs-content-template" type="text/x-handlebars-template"> {{#each tabs}} <div class="tab-content" data-tab-content="{{id}}">{{content}}</div> {{/each}} </script> </div>
and i'm writing function fill future form when double click on tab. i've managed how id , don't understand how name , content values. i've tried use jquery .text()
function, i've failed. here function:
$(function() { $("#tabsid").on("dblclick", "li", function(evt) { evt.preventdefault(); var id = $(this).data("tabcontent"); //var name = ? //var content = ? $('#inputindex').val(id); //$('#inputtitle').val(name); //$('#textareacontent').val(content); }); });
var id = $(this).data("tab-content"); var name = $(this).text(); // content nth element in other list (using index of li clicked) var content = $('#tabs-content-template .tab-content').eq($(this).index()).text();
note: works same collection used both lis , tab divs. otherwise need find via data-tab-content
attribute.
Comments
Post a Comment