I'm having some trouble with this:
template = $("#template"); $(template).attr("id", "newid"); $(template).appendTo("body");
What I want to do is assign an id to the template, then amend the content. Trouble is, I am currently referring to the actual template element, and so the id is changing that. On using this template again, I cannot select as the id is different.
Any advice on optimal approach?
Clone the object:
template = $("#template").clone(); template.attr("id","newid"); template.appendTo("body");
The HTML5 provides a template
element:
contents = $('#template').html(); copy = $('<div id="copy"></div>'); $('body').append(copy.append(contents));
The HTML part:
<html> <body> <template id='template'> </template> </body> </html>
The clone
method is not sufficient.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With