Zhongde Liu

This is my personal "Clipboard" of web development stuff I come across


Leave a comment

Note: Whitespace raises jQuery error (Ajax, jQuery 1.9)

Just stumbled upon a bug/feature when migrating to jQuery 1.9.

So the case is: You are trying to convert following String:

"   <div>Hallo</div>"

into a jQuery object. Pay attention to the leading whitespace.

Prior to 1.9 you get what you would expect. With 1.9, you will get an error.  Reason is this core change, documented here http://jquery.com/upgrade-guide/1.9/#jquery-htmlstring-versus-jquery-selectorstring. As I’m not the only one with this issue, there are already several posts about it (the intention, the pros, contras…). This is the according thread in the jQuery tracker: http://bugs.jquery.com/ticket/13223 .

There is also mentioned to re-implement the old behavior.