{"name":"last","type":"method","title":".last()","deprecated":null,"removed":null,"desc":"Reduce the set of matched elements to the final one in the set.","categories":["traversing/filtering","version/1.4"],"entries":[{"return":"jQuery","signatures":{"added":"1.4"},"examples":{"desc":"Highlight the last span in a paragraph.","css":"\n .highlight {\n background-color: yellow;\n }\n","code":"\n$( \"p span\" ).last().addClass( \"highlight\" );\n","html":"\n

Look: This is some text in a paragraph. This is a note about it.

\n"},"longdesc":"\n

Given a jQuery object that represents a set of DOM elements, the .last() method constructs a new jQuery object from the last element in that set.

\n

Consider a page with a simple list on it:

\n
\n<ul>\n  <li>list item 1</li>\n  <li>list item 2</li>\n  <li>list item 3</li>\n  <li>list item 4</li>\n  <li>list item 5</li>\n</ul>\n    
\n

We can apply this method to the set of list items:

\n
\n$( \"li\" ).last().css( \"background-color\", \"red\" );\n    
\n

The result of this call is a red background for the final item.

\n "}]}