Tag Archives: jquery training course

jQuery eq method


jQuery eq method() finds the element at specified index.


Syntax of jQuery eq Method

$(selector).eq(index);

Index :
– Index of element can be positive or negative number.

jQuery eq method Example 1

jQuery eq() Method – Example


Try it »

jQuery each method


jQuery each method() uses a function to iterate for each matching element. ie. function executes for each matching element.


Syntax of jQuery each Method

$(selector).each(function(Integer index, Element element ));

Function :
Index – Current Index of selector.
element Current element.

Let us understand it very basic example :
Suppose We have following elements-


  • Item 1
  • Item 2
  • Item 3

Let us select all li items and iterate them-

$( "li" ).each(function( index, elem) {
  console.log( index + ": " + $( elem ).text() );
});

or

$( "li" ).each(function( index ) {
  console.log( index + ": " + $( this ).text() );
});

The following message will be logged-

0: Item 1
1: Item 2
2: Item 3

jQuery each method Example 1

jQuery each() Method – Example


Try it »

jQuery contents Method


Get children of each element including text and comment nodes.


Syntax : jQuery contents() Method

$(selector).contents();

Note : It does not requires any argument.

jQuery contents Method Example

jQuery contents() Method Example with Syntax


Try it »

jQuery closest Method


jQuery closest Method :It is used to get first ancestor element of the current selection. If you want to get first ancestor element of the selected element use closest method which accepts filter as input parameter.


Syntax of jQuery closest Method

Here is syntax for closest Method example in jQuery –

$(selector).closest(filter);

filter String containing the selector expression for matching the elements.

jQuery Traversing – closest Example

jQuery closest() Method – Example

Try it »

The above code will produce following result-

Note : This is image of the output. To run this demo click on the above “Try it” button.

jQuery closest Method

jQuery children() Method


Get all the elements of the selected element.


Syntax : jQuery Traversing – children() Method

$(selector).children([selector element]);

[selector element] String containing the selector expression for matching the elements.

jQuery Traversing – children() Example 1

jQuery children() Method with syntax


Try it »

jQuery Traversing – children() Example 2

jQuery children() Method with syntax


Try it »

jQuery addBack() Method


jQuery addBack() Method Adds the previous set of elements to the current set.


Syntax of jQuery Traversing – addBack() Method

$(selector).addBack([selector element]);

jQuery addBack() Method – Example


Try it »

jQuery Traversing


jQuery traversing : jQuery Traversing stands traverse the Html DOM based on the element’s relationship. jQuery Traversing is used to filter the html elements based on the element’s relationship with the other elements.


Basic Example Of jQuery Traversing

Lets Start with very basic example.

jQuery CallBack


jQuery Callback function is called when current action is completed. Example – When slideDown effect(action) is completed.


jQuery CallBack functions example

In the below example callback function is executed when the show effect is completed.

jQuery CallBack functions example


    

Try it »

jQuery chaining animations


jQuery chaining animations is explained with example and demo.


jQuery chaining animations example and code

In the example we going to add chaining animations in the divs

First Div
Second Div
Third Div

jQuery selector chaining example


    

Try it »