Hardening Instructions: Select the element that belongs to the first (last) position in the collection of child elements in its parent element and all sibling elements
Note and: The difference between first:last
Instance:
<! DOCTYPE html>;} Html{font:15px/1.2em ' imitation '; color: #000;}#demo {width:850px;height:450px;margin:75px auto;} P{white-space:pre-Wrap;} . div-second{border:1px solid #921; margin:10px 0;padding:0;} Div> *{margin:5px 0; cursor:pointer;}</style><script type= ' Text/javascript ' > $(function(){ /** Definition and usage: The First-child selector selects the first conforming element in the collection of child elements belonging to its parent element and all sibling elements tip: use: Las The T-child selector selects the last conforming element declaration in the collection of child elements belonging to its parent and all sibling elements: Use this selector to select multiple conforming elements*/ $('. Div-second p:first-child '). css ({' backgroundcolor ': ' #F33942 '),}); $('. Div-second p:last-child '). css ({' backgroundcolor ': ' #C39A6B '),}); });</script>
[jquery position selector: First-child:last-child] Hardening Description: Select the element that belongs to the first (last) position in the collection of child elements belonging to its parent element and all sibling elements