Pascut
Pascut

Reputation: 3434

How to write $.fn.functionName = (function() { in jQuery 3

I have lots of functions like: $.fn.functionName = (function() {

I call them using: $(this).functionName();

This is deprecated in jQuery 3, how can I rewrite the function definition in order to make it work well (just like before).

Do you know a Library that is able to (automatically) replace the deprecated jQuery sintax? There's the jquery migration tool: https://blog.jquery.com/2016/05/19/jquery-migrate-1-4-1-released-and-the-path-to-jquery-3-0/ but it doesn't help me too much.

Thank you.

EDIT

Example log from jQuery 3 migration tool:

JQMIGRATE: jQuery.fn.focus() event shorthand is deprecated

console.trace()

migrateWarn
jQuery.fn[name]
$.fn.functionName/this.initData
$.fn.functionName
<anonymous>
_onReady
$.obj

Upvotes: 0

Views: 554

Answers (2)

Pascut
Pascut

Reputation: 3434

I was using the "livequery" (https://plugins.jquery.com/livequery/) and inside it I was calling the $.fn.functionName.

I know, it's an old code, but that was the problem. As freedomn-m said in a comment, the $.fn.xxx is not deprecated. I hope this will help others too.

Upvotes: 0

Rinkesh
Rinkesh

Reputation: 132

You need to replace jQuery.fn.blur() to jQuery.fn.trigger('blur') and jQuery.fn.focus() to jQuery.fn.trigger('focus') as per this https://github.com/mervick/emojionearea/issues/217,

Upvotes: 2

Related Questions