jquery Lookup new Element code _jquery

Source: Internet
Author: User
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 (' Li ')->each (function (i) {
var obj = $ (this). Find (' a ')->eq (0);
$em = $ (' <em> ');//New EM element
$em. html (i);
$em. InsertBefore (obj),//Insert new elements in front of the found element
});
It's so convenient, ha!!!!.

questions about the Find method of jquery
Find (expr)
  
Searches for all elements that match the specified expression. This function is a good way to find the descendant elements of the element being processed.
All searches rely on jquery expressions to complete them. This expression can be written using the Css1-3 selector syntax.
  
return value
Jquery
  
Parameters
Expr (String): Expression used for lookup
  
Example
Start with all the paragraphs and further search for the following span element. Same as $ ("P span").
  
HTML Code:
  
Hello, how are are you?
JQuery Code:
  
$ ("P"). FIND ("span")
Results:
  
[Hello]
jquery Query |jquery lookup element |jquery Lookup Object
#id return value:array<element> #id
Overview
Matches an element based on the given ID.

If a selector contains special characters, it can be escaped with two slashes. See examples.

Parameters
Idstring
For searching, the value given in the id attribute of the element

Example
Describe:
Look for elements with ID "mydiv".

HTML Code:
<div id= "Notme" ><p>id= "Notme" </p></div>
<div id= "mydiv" >id= "mydiv" </div>jquery Code:
$ ("#myDiv"); Results:
[<div id= "mydiv" >id= "mydiv" </div>] Description:
Find elements that contain 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 based on the given element name elementstring a search element. The label name that points to the DOM node. Example Description: Finds 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 a given class. Parameter classstring a class to search for. An element can have multiple classes, as long as there is one fit that can be matched to. Example Description: Finds elements that all classes are "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&gt, <span class= "MyClass" >span class= "MyClass" </span>] Selector1, Selector2,selectorn return value: Array<element (s) >selector1,selector2,selectorn overview The elements that match each selector are merged and returned together. You can specify as many selectors as you want, and merge the matching elements into one result. Parameter selector1selector a valid selector selector2selector another valid selector selectorn (optional) selector any number of valid selectors sample descriptions: Find the element that matches any one of the classes. 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&gt, <p class= "MyClass" >p class= "MyClass" &LT;/P&GT; <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.