document.createElement no funciona
Estoy creando un plugin usando la biblioteca jQuery.
Aqui estoy almacenandoString.prototype en una variable, entonces estoy usando esta variable para extender mi objeto Sting. Y esto está funcionando bien.
// 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());
En el siguiente caso estoy creando m.funcion xyz que se almacena ena B C variable y esto también está funcionando bien.
function xyz(x){
alert(x)
}
var abc = xyz;
// working fine
abc("yogesh kumar");
En el último caso estoy almacenando.document.createElement en una variableetiqueta y usando la etiqueta para crear un botón. Pero esto no está funcionando.
var tag=document.createElement;
$(document.createElement("button")).html("document.Element").appendTo("#myDiv");
// not working
$(tag("button")).html("tag").appendTo("#myDiv");
Por favor revise el enlace en jsFiddle:
Error:
En cromo
Error no detectado: invocación ilegalen Firefox
Error: NS_ERROR_XPC_BAD_CONVERT_JS: No se pudo convertir el argumento de JavaScript¿Por qué este error?
¿Cuál es la solución?