jQuery Selectors: The greater then gt selector

This entry is part 32 of 33 in the series jQuery Selectors


The greater then gt selector will filter the list to include elements after a specific zero-based index.

We use $(‘p:gt(1)’) as an example.

There are 3 <p> elements in the example, only the last <p> element will be highlighted with yellow background.

<!DOCTYPE html>
<head lang='en'>
    <meta charset='UTF-8'>
    <title>Codecrawl.com - HTML5</title>
    <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
        $(function () {
            $('p:gt(1)').css('background-color', 'yellow');


        <p>Ushuaia is the capital of Tierra del Fuego in Argentina</p>
        <p>It is commonly regarded as the southernmost city in the world.</p>

        <p>They also built a railway now a tourist attraction known as the End of the World Train</p>


The less then lt will do the reverse of gt as shown by the link button below.

Series Navigation<< jQuery Selectors: Applying indexed selector to table row
jQuery Selectors: Selecting an animated object >>

Leave a comment

Leave a Reply