Related actions on Li tags--8 ways to get the contents of the first element of the LI tag
1. Alert ($ ("Ul>li"). First (). html ());
2. Alert ($ (' Ul>li '). EQ (0). html ());
3. Alert ($ (' Ul>li:nth-child (1) '). html ());
4. Alert ($ (' ul '). Children () [0].innerhtml];
5. Alert ($ (' Ul>li ') [0].innerhtml];
6. Alert ($ (' ul '). Find ("Li") [0].innerhtml];
7. Alert ($ (' ul '). Contents (). Filter ("Li") [0].innerhtml];
8. Alert ($ ("Ul>li"). Get (0). InnerHTML);
Note: the contents () method gets the child nodes of each element in the matching element collection, including the text and comment nodes.
The filter () method reduces the set of matching elements to the element that matches the specified selector.
Similar to the. contents () and. Children () methods, the former contains text nodes and HTML elements in the resulting JQuery object
We are not allowed to use $ (' ul ') directly here. Contents () Need to use $ (' ul '). Contents (). Filter ("Li")
Front-End Learning notes (Zepto or jquery)--related actions on Li Tags (ii)