Vivek Goel Vivek Goel - 1 year ago 99
jQuery Question

How to select all element leaving first element?

I have jquery selector like

$("li a")

how can I modify it so it select all elements leaving first anchor tag ?

Jon Jon
Answer Source

You can use the :gt selector:

$("li a:gt(0)")

Update: If you are interested in performance, the fastest by far is

$("li a").slice(1)

about which the docs say:

Because :gt() is a jQuery extension and not part of the CSS specification, queries using :gt() cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method. For better performance in modern browsers, use $("your-pure-css-selector").slice(index) instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download