Review
// Html
<Div class = "DV">
<Ul>
<Li>
<A href = "xx.com"> XX </a>
</LI>
<Li>
<A href = "aa.com"> AA </a>
</LI>
<Li>
<A href = "bb.com"> BB </a>
</LI>
</Ul>
<Ul> </ul>
</Div>
// JS
$ ('. DV'). Find ('ul ')-> eq (0)-> Find ('lil')-> each (function (I ){
VaR OBJ = $ (this). Find ('A')-> eq (0 );
$ Em = $ ('<em>'); // creates an EM element.
Receivem.html (I );
$ Em. insertbefore (OBJ); // Insert the new element to the front of the searched element.
});
This is really convenient !!!!
Question about jquery's find Method
Find (expr)
Searches for all elements that match the specified expression. This function is a good way to find the child element of the element being processed.
All searches rely on jquery expressions. This expression can be written using the selector syntax of the CSS1-3.
Return Value
Jquery
Parameters
Expr (string): the expression used for searching.
Example
Search for the following span element from all paragraphs. Same as $ ("P span.
HtmlCode:
Hello, how are you?
Jquery code:
$ ("P"). Find ("span ")
Result:
[Hello]
Jquery query | jquery search element | jquery search object
# ID return value: array <element> # ID
Overview
Matches an element based on the given ID.
If the selector contains special characters, two slashes can be used for escape. See examples.
Parameters
Idstring
Used for search, by the value specified in the element ID attribute
Example
Description:
Find the element whose ID is "mydiv.
HTML code:
<Div id = "notme"> <p> id = "notme" </P> </div>
<Div id = "mydiv"> id = "mydiv" </div> jquery code:
$ ("# Mydiv"); Result:
[<Div id = "mydiv"> id = "mydiv" </div>] Description:
Search for elements with special characters
HTML code:
<Span id = "foo: bar"> </span>
<Span id = "foo [bar]"> </span>
<Span id = "foo. Bar"> </span> jquery code:
# Foo \: bar
# Foo \ [Bar \]
# Foo \. barelement return value: array <element (s)> element overview matches all element parameters elementstring with a given element name for search. The name of the tag pointing to the DOM node. Example Description: Find a div element. HTML code: <div> div1 </div>
<Div> div2 </div>
<Span> span </span> jquery code: $ ("Div"); Result: [<div> div1 </div>, <div> div2 </div>]. class return value: array <element (s)>. class overview matches elements based on the given class. The classstring parameter is a class used for search. An element can have multiple classes, and can be matched as long as there is a conformity. Example Description: Find all elements of the class "myclass". HTML code: <Div class = "notme"> Div class = "notme" </div>
<Div class = "myclass"> Div class = "myclass" </div>
<SPAN class = "myclass"> SPAN class = "myclass" </span> jquery code: $ (". myclass "); Result: [<Div class =" myclass "> Div class =" myclass "</div>, <SPAN class = "myclass"> SPAN class = "myclass" </span>] selector1, selector2, selectorn return value: array <element (s)> selector1, selector2, selectorn overview combines the elements matched by each selector and returns them together. You can specify any number of selectors and merge the matched elements into a single result. The selector1selector parameter is a valid selector2selector and another valid selectorn (optional) Multiple valid selector. Example Description: Find an element that matches any class. HTML code: <div> Div </div>
<P class = "myclass"> P class = "myclass" </P>
<Span> span </span>
<P class = "notmyclass"> P class = "notmyclass" </P> jquery code: $ ("Div, span, P. myclass ") Result: [<div> Div </div>, <P class =" myclass "> P class =" myclass "</P>, <span> span </span>]