views:

44

answers:

2

Hello everybody.
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

+3  A: 

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 ($=)?

Nick Craver
Thanks, that is what I was not sure about, I removed the "@" from every selector, but that causes the plugin to stop working all together.
jnkrois
@jnkrois - What is the markup you're running against? It would be `#myImage` if it was *just* the ID, but it must have intended a starts with, ends with, contains, etc...if you posted the element markup, it would be easier to tell.
Nick Craver
Thanks Nick, I really would not like to post some of the code, because I don't understand it very well myself, so I won't waste your time, but I do appreciate your help.Thanks
jnkrois
@jnkrois - What does the `<img />` tag look like? the `id="something"` is what this is after..does it start with "myImage", end with it, contain it?
Nick Craver
jnkrois
@jnkrois - Welcome! :)
Nick Craver
+1  A: 

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 :)

NM