jquery - Acessing current object from nested function -
How can I pass $ (this) object for the function inside the click event
< Code> $ ('# mainwrap img'). Click (function () {mcImageManager.browse ({oninsert: function (o) {src = o.focusedFile.url; $ (this) Attr ("src", src);}});}); Any suggestions would be greatly appreciated.
This is a special variable - each time the function is entered, Takes it to a new value. In this case, external code is this is available in the internal function, you can tie a new variable outside the nested function: $ ('#mainwrap img'). Click (function () {var $ this = $ (this); // new variable here mcImageManager.browse ({oninsert: function (o) {src = o.focusedFile.url; $ this.attr ("src", Src); // is referenced}});});
Comments
Post a Comment