Answers for "jquery add a new html element based on a template with variables"

0

jquery add a new html element based on a template with variables

<script id="hidden-template" type="text/x-custom-template">
    <tr>
        <td>Foo</td>
        <td>Bar</td>
    <tr>
</script>

then in javascript:

var template = $('#hidden-template').html();
// the following line is to set some value in the template
// if the template code is static you can skip the following line 
template.find('#en-element-to-set-its-value').html("<p>This is the new value</p>");
$('button.addRow').click(function() {
    $('#targetTable').append(template);
});
Posted by: Guest on November-24-2020

Code answers related to "jquery add a new html element based on a template with variables"

Browse Popular Code Answers by Language