control-freak-ide/Control-Freak-Documentation/jQuery/docs/entries/first.json
plastic-hub-dev-node-saturn 538369cff7 latest
2021-05-12 18:35:18 +02:00

1 line
1.3 KiB
JSON

{"name":"first","type":"method","title":".first()","deprecated":null,"removed":null,"desc":"Reduce the set of matched elements to the first in the set.","categories":["traversing/filtering","version/1.4"],"entries":[{"return":"jQuery","signatures":{"added":"1.4"},"examples":{"desc":"Highlight the first span in a paragraph.","css":"\n .highlight{\n background-color: yellow\n }\n","code":"\n$( \"p span\" ).first().addClass( \"highlight\" );\n","html":"\n<p>\n <span>Look:</span>\n <span>This is some text in a paragraph.</span>\n <span>This is a note about it.</span>\n</p>\n"},"longdesc":"\n <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 element in that set.</p>\n <p>Consider a page with a simple list on it:</p>\n <pre><code>\n&lt;ul&gt;\n &lt;li&gt;list item 1&lt;/li&gt;\n &lt;li&gt;list item 2&lt;/li&gt;\n &lt;li&gt;list item 3&lt;/li&gt;\n &lt;li&gt;list item 4&lt;/li&gt;\n &lt;li&gt;list item 5&lt;/li&gt;\n&lt;/ul&gt;\n </code></pre>\n <p>We can apply this method to the set of list items:</p>\n <pre><code>\n$( \"li\" ).first().css( \"background-color\", \"red\" );\n </code></pre>\n <p>The result of this call is a red background for the first item.</p>\n "}]}