Syntax error, unrecognized expression: :nth-child #5141

Closed
ottoville opened this Issue Oct 8, 2012 · 7 comments

5 participants

@ottoville

When sending form, page stuck in transaction and raise error in console:
Uncaught Error: Syntax error, unrecognized expression: :nth-child jquery-1.8.2.min.js:2

@ottoville

I figured out where the problem is.
It happens when there is not any list item in navbar, so following code will break jquery mobile:
[div data-role="navbar"][ul] [/ul]
[/div]

(Editor didnt allow me to post html here so I changed tags)

Seems this old bug have came back #1107

@jaspermdegroot
jQuery Foundation member

@ottoville

You can call the navbar plugin to enhance the navbar after you appended the list items. Without list items there is nothing to enhance yet, so you can leave out data-role="navbar". That data- attribute is only used to auto initialize the navbar plugin. Example: http://jsbin.com/ikisux/35/edit

However, it should also be possible to enhance the navbar by using trigger("create"). In that case you do need to set data-role="navbar" and the issue you reported occurs. Test page: http://jsbin.com/ikisux/36/edit
Related issue: #4990

The error only occurs with jQuery core 1.8.x, because of changes in Sizzle. It's not a regression because with one list item there is no issue and that's what #1107 was about. The reason the issue wasn't noticeable before was in fact a bug in Sizzle.

@jaspermdegroot
jQuery Foundation member

@ottoville

Use tripple backticks to add code blocks to your post. See http://github.github.com/github-flavored-markdown/

@allannienhuis

This one caught me when I managed to close my ul incorrectly - I used <ul>instead of </ul> to (incorrectly) close the list. The browser (chrome) happily closed BOTH ul elements, leaving the second one emtpy (without <li> elements) and so triggering the above bug. This was a pretty subtle typo, so thought I'd share the experience in case some else is looking at this and saying to themselves (like I did) "but I've got <li> elments in my list!!!!" :)

@danman01

this worked for me after upgrading to query 1.8.2 and getting the nth child error with jquery mobile

"You can call the navbar plugin to enhance the navbar after you appended the list items. Without list items there is nothing to enhance yet, so you can leave out data-role="navbar". That data- attribute is only used to auto initialize the navbar plugin. Example: http://jsbin.com/ikisux/35/edit"

I just checked for existence of data, and if there was not any, did not place the navbar in my page.

Thanks!

@dde
dde commented Feb 8, 2013

Had this error with div data-role="navbar" containing empty ul list (i.e. no li's)

inserted check for 0 children in $.fn.grid at 5556 (1.3.0-rc.1)

if ( $kids.length == 0 )
return;

seemed to fix the problem.

@jaspermdegroot
jQuery Foundation member

Closing as duplicate of #6337.

@jaspermdegroot jaspermdegroot referenced this issue May 13, 2014
Closed

Navbar Review #7359

0 of 12 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment