Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

30 lines (30 sloc) 1.331 kb
<?xml version="1.0"?>
<entry type="method" name="first" return="jQuery">
<desc>Reduce the set of matched elements to the first in the set.</desc>
<longdesc>[<p>Given a jQuery object that represents a set of DOM elements, the <code>.first()</code> method constructs a new jQuery object from the first matching element.</p>
<p>Consider a page with a simple list on it:</p>
&lt;li&gt;list item 1&lt;/li&gt;
&lt;li&gt;list item 2&lt;/li&gt;
&lt;li&gt;list item 3&lt;/li&gt;
&lt;li&gt;list item 4&lt;/li&gt;
&lt;li&gt;list item 5&lt;/li&gt;
<p>We can apply this method to the set of list items:</p>
<pre><code>$('li').first().css('background-color', 'red');</code></pre>
<p>The result of this call is a red background for the first item.</p></longdesc>
<desc>Highlight the first span in a paragraph.</desc>
<css><![CDATA[.highlight{background-color: yellow}]]></css>
<code><![CDATA[$("p span").first().addClass('highlight');]]></code>
<html><![CDATA[<p><span>Look:</span> <span>This is some text in a paragraph.</span> <span>This is a note about it.</span></p>]]></html>
<category slug="traversing/filtering"/>
<category slug="version/1.4"/>
Jump to Line
Something went wrong with that request. Please try again.