I wanted to choose the Nth LI in all ULs before, so I wrote this: $('ul li:eq(N-1)') . The result is to select the Nth element in the result obtained by the LI below UL. This thinking is wrong (because it is quite pleasing to: select the Nth LI below all ULs. In my mind, $('ul li:eq(N-1)') has been analyzed separately by me. It would be great if the official can make this chain writing method, for example: $('ul').$('li:eq(N-1)')). It seems that this writing method needs to be written after I learn more and then write a framework by myself.
Since I was confused, I suddenly felt that the selector was quite profound, so it would be easier to use it well.
Since you cannot choose at the same time, just use traversal. The following is an example. As for the writing of traversal, I like a lot.
Post code (select the third LI in each UL):
<!DOCTYPE html><html><head><meta charset="utf-8" /><script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script></head><body><ul><li>I am the first LI in the first UL</li><li>I am the second LI in the first UL</li></ul><ul><li>I am the third LI in the second UL</li></ul><script type="text/javascript">$.each($('ul'), function() {var li=$(this).children().last();alert($(li).text());//In fact, I'm quite curious why it cannot be equivalent to alert(li.innerHTML); isn't it said that dom and jq objects are converted to each other, why is it written as undefined??});</script></body></html>The above article JQ selector_The implementation method of selecting the Nth sub-element of similar elements is all the content I have shared with you. I hope you can give you a reference and I hope you can support Wulin.com more.