Tom Rider
Tom Rider

Reputation: 2805

how to bind event on all elements except first 1 in jquery

I want to bind hover event on all .menu class element except first element for this i wrote the following code :

        $(".menu:not(:first-child')").hover(function () {
        },
        function () {
        });

But this is not working. Whats the problem ?

Upvotes: 1

Views: 228

Answers (4)

Richard
Richard

Reputation: 8280

jQuery's slice method

$('.menu').slice(1).hover(function () {
    // in
}, function () {
    // out
});​

Just to be different...

Upvotes: 1

Diode
Diode

Reputation: 25135

$(".menu").not(":first-child")

or

$(".menu").not(":eq(0)")

Upvotes: 2

David Michael Harrison
David Michael Harrison

Reputation: 374

 $(".menu:not(:first)").hover(function() {

 },
 function () {
 });

Upvotes: 0

Sirwan Afifi
Sirwan Afifi

Reputation: 10824

use this code :

$('.menu').not(":first")

Upvotes: 0

Related Questions