<ul class= "First" > <li class= "foo" >list item 1</li> <li>list Item 2</li> <li class= "Bar" >list Item 3</li></ul><ul class= "Second" > <li class= "foo" >list item 1</li> <li>list Item 2</li> <li class= "bar" >list Item 3</li></ul>$ (' Ul.first '). Find ('. Foo '). css (' background-color ', ' Red '). end (). Find ('. Bar '). CSS (' background-color ', ' green ');
Back to a recent "destructive" operation.
This command chain retrieves the items in the first list that have the class name Foo and sets their background to red. End () Restores the object to the state before the call to find (), so the second find () looks for the '. Bar ' in <ul class= "First" > instead of <li class= "foo" > in the list and will match The background of the element is set to green. The final result is that item 1 and item 3 in the first list are set with a colored background, and the items in the second list have no changes.
A detailed explanation of the end () method of JQuery