document.createElement not working

前端 未结 5 1752
南方客
南方客 2021-01-16 06:20

I am creating a plugin using jQuery library.

Here i am storing String.prototype in a variable then i am using this variable to extend my Sting objec

5条回答
  •  一整个雨季
    2021-01-16 07:16

    Use the bind() method for "assigning" the native JS method to a variable:

    var ce = document.createElement.bind(document);
    var elem = ce('div');
    alert(elem.nodeName);
    

    Works in modern browsers including IE9+. For older browsers, use a wrapper function.

提交回复
热议问题