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

1 line
2.2 KiB
JSON

{"name":"prevAll","type":"method","title":".prevAll()","deprecated":null,"removed":null,"desc":"Get all preceding siblings of each element in the set of matched elements, optionally filtered by a selector.","categories":["traversing/tree-traversal","version/1.2"],"entries":[{"return":"jQuery","signatures":{"added":"1.2","argument":{"desc":"A string containing a selector expression to match elements against.","name":"selector","optional":"true","type":"Selector"}},"examples":{"desc":"Locate all the divs preceding the last div and give them a class.","code":"\n$( \"div:last\" ).prevAll().addClass( \"before\" );\n","css":"\n div {\n width: 70px;\n height: 70px;\n background: #abc;\n border: 2px solid black;\n margin: 10px;\n float: left;\n }\n div.before {\n border-color: red;\n }\n","html":"\n<div></div>\n<div></div>\n<div></div>\n<div></div>\n"},"longdesc":"\n <p>Given a jQuery object that represents a set of DOM elements, the <code>.prevAll()</code> method searches through the predecessors of these elements in the DOM tree and construct a new jQuery object from the matching elements; the elements are returned in order beginning with the closest sibling.</p>\n <p>The method optionally accepts a selector expression of the same type that we can pass to the <code>$()</code> function. If the selector is supplied, the elements will be filtered by testing whether they match it.</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 class=\"third-item\"&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>If we begin at the third item, we can find the elements which come before it:</p>\n <pre><code>\n$( \"li.third-item\" ).prevAll().css( \"background-color\", \"red\" );\n </code></pre>\n <p>The result of this call is a red background behind items 1 and 2. Since we do not supply a selector expression, these preceding elements are unequivocally included as part of the object. If we had supplied one, the elements would be tested for a match before they were included.</p>\n "}]}