Is jQuery (..). Html () error in jQuery 1.3.2?
The code here does not return the expected:
jQuery('<div>Look here: [ jQuery0="null" ]</div>').html() Rather, you will get:
Look here: [ ] Download Source Package jQuery:
html: function( value ) { return value === undefined ? (this[0] ? this[0].innerHTML.replace(/ jQuery\d+="(?:\d+|null)"/g, "") : null) : this.empty().append( value ); }, What would be the motivation for .replace ? I donβt have time to go to the rest of jQuery, but such code makes me wonder if jQuery should be used in production at all.
This code is new in 1.3.2, it was not in 1.3.1. It seems to me that jQuery uses attributes whose names begin with "jQuery" to store data on elements, and this is a way not to expose you to when you request html.
This is clearly not a mistake. The author decided to remove this HTML before returning the string.
Does this affect your code? As with any library, you must carefully test your production code before deploying it.
What would be the motivation for .replace?
To hide the attributes used by jQuery for internal purposes.
code like this makes me wonder if jQuery should be used in production at all.
Yes, I had the same reaction. It's just incredibly messy. Trying to process HTML with regexp is the naive hack you expect from posters with new questions, not the behavior you hope to see in the framework, so many SO users worship.
This is not the only place jQuery shuts down trying to parse markup with regex; some of the selector files are broken too. These may be obscure corner cases, but for me it is a huge red flag indicating the wrong approach.