Please consider the following sample code:
The error appears because createElement()
returns a DOMElement which does not have an append()
method; that's only available on jQuery objects. You need to either wrap the DOMElement to a jQuery object or, better yet, create the element in jQuery:
$("#btn1").click(function(){
var btn = $('');
btn.prepend("Prepended text. ");
// add the btn to the DOM somewhere...
});