Bug Tracker

Opened 8 years ago

Closed 8 years ago

#10573 closed bug (invalid)

exception in jQuery(selector [, conext])

Reported by: ceddlyburge@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7b2
Keywords: Cc:
Blocked by: Blocking:

Description

This isn't exactly a bug but could maybe be handled better

If there is a <table> tag inside a <tr> tag, without an intervening <td> tag then jquery raises an exception when trying to do a selection on it. Other types of tags under a <tr> tag do not cause this problem.

jQuery selecting is also a bit unintuitive when there is not a root element to the passed in document, perhaps an informative error message would be useful here?

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 = '<table><tr><td><form action="" method="post"><table><tr><td></td></tr></table></form></td></tr></table>';        

var validhtml3 = '<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", invalidhtml); // crash here in ie, or a silent fail in decent browsers

I couldn't get jsfiddle to run it but here is the link anyway, the code is right I think.

http://jsfiddle.net/benny/HSZMz/3/

Change History (1)

comment:1 Changed 8 years ago by dmethvin

Resolution: invalid
Status: newclosed

Invalid HTML pretty much closes the ticket. Trying to anticipate and give reasonable error messages for every possible problem is just too difficult and takes a lot more code than we can afford to write.

Also, I should point out that there is no jQuery signature of the form jQuery(selector, htmlstring) .

http://api.jquery.com/jQuery/

Note: See TracTickets for help on using tickets.