I have this in my HTML:
<script id="tpl" type="text/template">
<div data-id="" class="line">
...
</div>
</script>
In JS I'm getting that template to add it into the HTML, then set each a data attribute, as:
$('.add-line').on('click', function(){
var tpl = $('#tpl').html()
$(tpl).data('id', 'TEST')
$(tpl).attr('data-id', 'TEST')
$('.target').append(tpl)
})
But none of these added have any data-id. What am I doing wrong?