jQuery “Object doesn't support this property or method” in Internet Explorer

前端 未结 3 734
自闭症患者
自闭症患者 2021-01-11 15:38

I am using jQuery to add some dynamic content to a website.

I am attempting to create a new DOM element on-demand using the following code:

container         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-11 16:08

    I don't know if it can help but I fixed my problem. Basically IE doesn't want to assign jquery object to an undefined variable.

    So what I did is declare this a local variable instead.

    Before:

    function foo() {
      bar = $('#bar');
    }
    

    After:

    function foo() {
      var bar = $('#bar');
    }
    

提交回复
热议问题