Jquery searches for new element code

Source: Internet
Author: User

// Html
<Div class = "DV">
<A href = "xx.com"> XX </a>
<A href = "aa.com"> AA </a>
<A href = "bb.com"> BB </a>
<Ul> </ul>
// 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

Expr (string): the expression used for searching.

Search for the following span element from all paragraphs. Same as $ ("P span.


Hello, how are you?
Jquery code:

$ ("P"). Find ("span ")

Jquery query | jquery search element | jquery search object
# ID return value: array <element> # ID
Matches an element based on the given ID.

If the selector contains special characters, two slashes can be used for escape. See examples.

Used for search, by the value specified in the element ID attribute

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>]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.