jquery prevAll() method
Translation results:
prev
UK[prɪv] 美[prɪv]
[medical]Prevention
all
英[ɔ:l] 美[ɔl]
adj. All; everything; all kinds; extreme, as much as possible
pron. All; everything; everyone , every thing; all situations
adv.entirely; completely; every; very
n.all;[often as A-]whole;[often with my, your, Used with his, her, etc.] everything that (someone) has
jquery prevAll() methodsyntax
Function: prevAll() obtains the previous sibling elements of each element in the current matching element set. Filtering with a selector is optional.
Syntax: .prevAll(selector)
Parameters:
Parameter | Description |
selector | String value, containing the selector expression used to match elements. |
Description: If given a jQuery object that represents a collection of DOM elements, the .prevAll() method allows us to search in front of these elements in the DOM tree sibling elements and constructs a new jQuery object with the matching element. This method accepts an optional selector expression of the same type as the argument we passed into the $() function. If this selector is applied, elements will be filtered by testing whether they match the selector.
jquery prevAll() methodexample
<!DOCTYPE html> <html> <head> <style> div { width:70px; height:70px; background:#abc; border:2px solid black; margin:10px; float:left; } div.before { border-color: red; } </style> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script> </head> <body> <div></div> <div></div> <div></div> <div></div> <script>$("div:last").prevAll().addClass("before");</script> </body> </html>
Click the "Run instance" button to view the online instance