Jquery throws object has no 'replace' on.animate method

Using jquery 1.7.1

this is a simple function I'm trying to run:

$('#large-boxes').dblclick(function(e){ var element = $(e.target); boxes.disappear(element); }); boxes = { disappear: function(element){ console.log(element); element.animate({ height: 0, width: 0, top: 0, left: 0 }, 100); }, } 

which displays this on the console at startup:

 boxes.js:60 [ <div id=​"4" class=​"ui-draggable">​</div>​ ] jquery.min.js:4 Uncaught TypeError: Object function () { var i; var newObj = (this instanceof Array) ? [] : {}; for (i in this) { if (i == 'clone') continue; if (this[i] && typeof this[i] == "object") { newObj[i] = this[i].clone(); } else newObj[i] = this[i] } return newObj; } has no method 'replace' 

At first, I thought that the brackets around an element of an element could point to an array, but it looks like it's just a jquery object designation.

The element animates correctly, and if I remove the .animate function and just set all the values ​​using .css, I won’t get an error.

Any ideas?

+4
source share
2 answers

you may need to add $(element) . It's hard to say how you actually call this function.

+1
source

Let me make a wild guess. It:

 Object function () { var i; var newObj = (this instanceof Array) ? [] : {}; ...... 

may be your own function that messed up the namespace of the object. IOW somewhere in your source code that you do, for example:

 Object.prototype.myclone = function() { ... } 

Now $ .fn.animate (prop, ...) will select this during the loop

 for( p in prop ) { .... 

because prop is just a regular Object:

 { height: 0, width: 0, top: 0, left: 0 } 

And from now on, your "myclone" has its own life, and the failure you see may be much later. The best answer I can give you is "grep newObj. *" Your source files and all your libraries. Just let us know if it shoots at the target ...

+1
source

Source: https://habr.com/ru/post/1391757/


All Articles