Q:

Exception in jQuery(selector [, context])

Can anybody tell me why I get an exception using the code below?
var invalidhtml = '<tr><div id="residualErrors" style="display:none;"></div><form action="" method="post"><table><tr><td></td></tr></table></form></tr>';  

var form = $("form", invalidhtml);

A:

The problem is that the html is invalid as there is no "td" element under the "tr" element. jQuery can normally handle this but if there is also a "table" included within the "tr" element somewhere then it raises an exception.
The original place where I had the problem was much more complicated html so I hope it helps somebody.
Any of the validhtml examples below work, the invalid one does not.
var invalidhtml = '<tr><form action="" method="post"><table><tr><td></td></tr></table>    </form></tr>';        

var validhtml = '<tr><form action="" method="post"></form></tr>';        

var validhtml2 = '<div><form action="" method="post"><table><tr><td></td></tr></table>    </form></div>';        

var validhtml3 = '<table><tr><td><form action="" method="post"><table><tr><td></td></tr></table></form></td></tr></table>';        

var validhtml4 = '<tr><td><form action="" method="post"><table><tr><td></td></tr></table>     </form></td></tr>';        

var form = $("form", validhtml);
form = $("form", validhtml2);
form = $("form", validhtml3);
form = $("form", validhtml4);
form = $("form", invalidhtml); // crash here in ie, proper browsers fail silently

