Stackoverflow Question Solution
http://stackoverflow.com/questions/14202699/document-createelement-not-working/14202853#comment19694680_14202853
by yoku2010
HTML
<div id="myDiv"></div>
JavaScript
// String Prototyping store in a variable
// Save bytes in the minified version of js
var StrProto = String.prototype;
String.prototype.toProperCase = function () {
return this.replace(/\w\S*/g, function (txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
};
// working fine
alert("yogesh kumar".toProperCase());
function xyz(x) {
alert(x)
}
var abc = xyz;
// working fine
abc("yogesh kumar".toProperCase());
// same i try with document.createElement
// but i got error....
// why this error?
// what is the solution?
// please help me...thanks in advance
var tag = document.createElement;
$(document.createElement("button")).html("document.Element").appendTo("#myDiv");
// not working (error)
// $(tag("button")).html("tag").appendTo("#myDiv");
// reason: it is no longer being called as a member of document
// tag.call(document,"tagName") will work
// now works (resolved)
$(tag.call(document,"button")).html("tag").appendTo("#myDiv");
// Error:
// in Chrome
// Uncaught TypeError: Illegal invocation
// in Firefox
// Error: NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument