Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

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

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

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

ottoville opened this issue Oct 8, 2012 · 7 comments

Comments

@ottoville
Copy link

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
Copy link
Author

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
Copy link
Contributor

@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
Copy link
Contributor

@ottoville

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

@allannienhuis
Copy link

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
Copy link

danman01 commented Nov 3, 2012

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
Copy link

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
Copy link
Contributor

Closing as duplicate of #6337.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants