I’m confronted by a strange jQuery problem.
I was asked to help figure out why a site broke recently. They are loading the latest version of jQuery from a CDN, and making liberal use of it, including features like attr. I have very little experience with jQuery; I’ve heard attr is broken, and I’ve seen that it performs poorly, so I never use it.
Anyway, this code has things like foo = $(this).attr('class').split(' ')[0] all over the place, and all of that broke recently. Apparently, attr used to return a String, and now it returns a jQuery object. It’s simple enough to go through and change code like this to a somewhat more sensible foo = this.className.split(' ')[0], but I wonder if I’m going about this the wrong way.
So, my question is: Is there a jQuery configuration setting to get attr to act like it did in the previous version, and return a String? If not, has anyone else run into this problem? How did you handle it?
The short answer is no.
The long answer (along with this is probably not the best way to do this *thanks @GGG) is that this seems to be related to the way JQuery refactored .prop() to take make .attr() behave better in version 1.6. Without going BACK to previous versions, you cannot ask JQuery to change its behavior.
ref: http://api.jquery.com/prop/