Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery - not first

How can I say..

On Click .not.first() div
alert('Yeah you clicked a div which is not the first one!');

My actual code:

this.$('thumbnails').children().click(function() {

                $('#video').animate({width: 164, height: 20, top: 475, marginLeft: 262},0)

       $('.flv').animate({left: 2222, opacity: '0'},0).css('display', 'none')
        $('.close').animate({opacity: '0'},0)
                clicked = 0

            });
like image 332
Tomkay Avatar asked Nov 29 '10 14:11

Tomkay


People also ask

What is not () in jQuery?

The not() is an inbuilt function in jQuery which is just opposite to the filter() method. This function will return all the element which is not matched with the selected element with the particular “id” or “class”. Syntax: $(selector).not(A) The selector is the selected element which is not to be selected.

How do you say not in jQuery?

jQuery :not() SelectorThe :not() selector selects all elements except the specified element.

Is not condition in jQuery?

jQuery not() Method: This method returns elements that do not match a defined condition. This method specifies a condition. Elements that do not match the condition are returned, and those that match will be removed. Mostly this method is used to remove one or more than one elements from a group of selected elements.

Is first child jQuery?

It is a jQuery Selector used to select every element that is the first child of its parent. Return Value: It selects and returns the first child element of its parent.


2 Answers

There's a :gt() (greater-than-index) selector or .slice(1) (@bobince's preference :), your question translated literally would be:

$("div:gt(0)").click(function() {
  alert('Yeah you clicked a div which is not the first one!');
});
//or...
$("div").slice(1).click(function() {
  alert('Yeah you clicked a div which is not the first one!');
});

For your updated question:

$('thumbnails').children(":gt(0)").click(function() {
   $('#video').css({width: 164, height: 20, top: 475, marginLeft: 262});
   $('.flv').css({left: 2222, opacity: '0'}).hide();
   $('.close').css({opacity: '0'});
   clicked = 0;
});
//or...
$('thumbnails').children().slice(1).click(function() {
   $('#video').css({width: 164, height: 20, top: 475, marginLeft: 262});
   $('.flv').css({left: 2222, opacity: '0'}).hide();
   $('.close').css({opacity: '0'});
   clicked = 0;
});

Note the use of .css(), if you want to make instant non-animated style changes, use this istead.

like image 176
Nick Craver Avatar answered Oct 13 '22 23:10

Nick Craver


$(div).not(":first").click(function(){
   alert("Yeah you clicked a div which is not the first one!);
});

see :first and .not from the jquery docs.

$('thumbnails').children().not(":first").click(function() {
    $('#video').animate({width: 164, height: 20, top: 475, marginLeft: 262},0)
    $('.flv').animate({left: 2222, opacity: '0'},0).css('display', 'none')
    $('.close').animate({opacity: '0'},0)
        clicked = 0
});

Would be the answer for the update to your question.

like image 34
dotty Avatar answered Oct 13 '22 22:10

dotty