简体   繁体   中英

Upgrade jQuery plugins to latest version

I have quick question about jQuery plugins, hope somebody out there has some advice. I'm working with a jQuery plugin that has been working as expected, but in the last couple of days we upgraded from jQuery 1.1.4 to 1.4.2.
After a lot of debugging, I was able to realize that in the old plugin, selectors are written as follows:

 $('img[@id&=myImage]').each ...

Once we upgraded to the latest version of jQuery, I started getting JavaScript errors as follows:

uncaught exception: Syntax error, unrecognized expression: [@id&=myImage]

As you can see, the selector includes an "@" symbol (which I believe is the one causing the error) and after consulting the jQuery documentation about all the different type of selectors, I was not able to find whether this was correct or not, given that it worked before and now it doesn't.

At this point I have to figure out if I can use the old plugin with the new version of jQuery or if I have to come up with an alternative solution.

I'd appreciate any advice.
Thanks

The @ for attribute selectors was removed in jQuery 1.3 , just take it out, like this:

$('img[id^=myImage]').each(...);

Also I'm not sure what &= would have referred to, I think you want one of the other attribute selectors here , possibly starts-with ( ^= ) or ends-with ( $= ) ?

It all boils down to the pros and cons of upgrading.
Pros for upgrading are :

  1. The newer version definitely has a lot of improvements in terms of speed/performance and also bug fixes.
  2. New plugins of jQuery would probably require the new version and in the long term you might benefit from these .

Cons :

  1. You need to take care of all the plugins that break in the new version . Like the one in question ( I guess you could just take out the @ symbol and it should work ) .
  2. How many such plugin you are using and what is the current size of your js code that can break with this upgrade. The jQuery release documentations like this and this might be a starting point

You could take a decision based on the cost and time estimate of the above. If there are just 1 or 2 plugins that needs a little tweaking, I would say definitely go ahead and upgrade .
However if you have a dozen plugin that break and you would have to rewrite almost 50 - 60% of your frontend code again, then you have a tough call to make :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM