JQuery Select First or Last Element

From CoderLearner
Jump to: navigation, search

Search for first or last element

Sometime it is beneficial to find the last or the first element.

Example 1

Assign css color to blue for the first p element.

// <div>My First</div> is blue color

<div>My First</div>
<p>My second</p>
<div>Second Div</div>
<div>Third Div</div>

Example 2

Assign css color to blue for the last element.

// <p>Fourth</p> 


Example 3

<!DOCTYPE html>
      <title>odd even</title>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            background-color: #6699CC;

            background-color: #999900;


Try It

<seo metagenerator="jquery tutorial" title="Jquery/Ajax" metakeywords="jquery greater,jquery gt, jquery lt, less then, odd jquery,jquery find element, even jquery,jquery event, jquery mouse click, jquery double click, jquery hover, jquery string, jquery array, jquery button, jquery attriubtes" metadescription="jquery button, jquery attriubte, jquery example, jquery tutorial, jquery sample"/>