1

I have created widget which is using jquery latest version 1.11.1. When i adding my widget into 3rd party website.

And 3rd party website have lower version jquery e.g. 1.5 in my case (it could be any version). 3rd party website jquery don't have the latest function.

e.g Latest version function

 jQuery(document).on("click", function(e) { 
...
});

So i am getting error function is undefined. How to resolve this type of issue.

Or did i have created the widgets wrong way that depend on jquery? If anyone know how to implement java script widget that don't depend on 3rd party library like jquery different version.

9
  • intead of .on() use .live() Commented Feb 18, 2015 at 11:57
  • In jQuery 1.5, you have the [.delegate()][api.jquery.com/delegate/] Commented Feb 18, 2015 at 11:58
  • Yes i know the live function but if 3rd party website don't using jquery 1.5 in that case it will not work. it is static change. I want dynamic change. Becasuse i don't know the which jquery version 3rd party website is using it could be anyting. Commented Feb 18, 2015 at 12:01
  • if i don't found .on() event then i want to use .live() otherwise it will use the same Commented Feb 18, 2015 at 12:18
  • you can just use jQuery(document).click(function(e) { }) - why do you want to use .on() in this case as you are not using any delegation Commented Feb 18, 2015 at 12:19

5 Answers 5

1

If you are using event delegation, only then this answer applies

In jQuery 1.5, you have the .delegate() method, you can use that

$( "table" ).delegate( "td", "click", function() {
  $( this ).toggleClass( "chosen" );
});

Don't use .live() as it is removed in verions >= 1.9

Sign up to request clarification or add additional context in comments.

1 Comment

OP is simply attaching the click event, there is no need for event delegation.
0

The on method is not known in version 1.5

You should use this syntax instead:

jQuery(document).click(function(e) { 
...
});

Comments

0

jQuery(document).click(function(e) { here as there is no delegation

And for dynamic HTML use live event as it works in old jquery version and you Must use deprecated syntax as its using old jQuery.

if you have to deal with dynamically data use live()

1 Comment

the live event is not needed here as he is attaching to any click on the document, i doubt any new documents are added to the dom? :)
0

Jquery .on() is added in version 1.6+. for previous versions you need to use .live()

As you are not delegating the event, you can simply use .click() to attach the click event:

jQuery(document).click(function(e) { 
  ...
});

Comments

0

I don't think there is any direct/dynamic way to resolve your problem. Even if you resolve the problem with 'click' function. You may face problem with another function which is either not supported in lower version of JQuery or have different syntax/behavior.

e.g. few animations like 'fadeOut(1000)' may not be supported in lower version of JQuery(this is just example. You need to check whether these kind of APIs are supported or not.)

So practically you might have to just do trail and error. Test your JQuery widget/plugin with all available JQuery versions.

  1. You could figure out the Jquery version of the WebSite where you are deploying your widget. See if this is helpful to get the version. https://api.jquery.com/jquery-2/

  2. Depending on version you could use appropriate supported API e.g., live() for v1.5 and below AND .click() for higher versions.

You are good to go when everything works.

2 Comments

You may have to use e.g., both .live() and .on() in you widget/plugin using if...else or ?.. : depending on jquery version
i have find another way for my widget. I have put my widget in auto re-size iframe. that's the final solution i found. and it is working very well with any website. No javascript conflicts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.