saltcod
saltcod

Reputation: 2031

jQuery which selector for sub-elements?

I can't figure out which selector to use to get the items listed in a sub menu.

  1. List item
  2. List Item
  3. List item
    1. A
    2. B
    3. C

I want to paginate a list using Next/Prev but the sub menu won't show up. I want to show 5 items at a time, but when you hit next, you don't get the sub-list returned.

And the fiddle: http://jsfiddle.net/saltcod/bXKsZ/1/

Thanks

Upvotes: 1

Views: 2472

Answers (2)

Zach
Zach

Reputation: 11

Use the space char to indicate a descendant node.

$('ancestor descendant')

http://api.jquery.com/descendant-selector/

If you want a direct child node only, use >

$('parent>immediateChild')

http://api.jquery.com/child-selector/

Upvotes: 1

charlietfl
charlietfl

Reputation: 171669

This is going to hide all your sub LI's also.

$('ul li:gt(4)').hide();

Assume main UL id=list, hide only children LI's

 $('#list > li:gt(4)').hide();

EDIT: same issue with next/prev . Use a parent ID to define children, not UL since submenus also have UL

Upvotes: 1

Related Questions