//js $('.dv').find('ul')->eq(0)->find('li')->each(function( i){ var obj = $(this).find('a')->eq(0); $em = $('');//New em element $em.html(i); $em.insertBefore(obj);//Insert the new element in front of the found element }); How convenient! ! ! !
Questions about jQuery’s find method find(expr)
Search for all elements that match the specified expression. This function is a great way to find out the descendant elements of the element being processed. All searches rely on jQuery expressions. This expression can be written using CSS1-3 selector syntax.
Return value jQuery
Parameters expr (String): Expression used to find
Example Starting from all paragraphs, further Search for span elements below. Same as $("p span").
HTML code:
Hello, how are you? jQuery code:
$("p").find("span") Result :
[Hello] jquery query|jquery find element|jquery find object #id return value: Array#id Overview Matches an element based on the given ID.
If the selector contains special characters, they can be escaped with two slashes. See examples.
Parameters idString Used to search by the value given in the element's id attribute
Example Description: Find the ID for "myDiv" elements.
HTML code:
id="notMe"
id="myDiv"
jQuery code: $ ("#myDiv");Result: [
id="myDiv"
] Description: Find elements containing special characters
HTML code:
jQuery code: #foo\:bar #foo\[bar\] #foo\. barelement return value: Arrayelement overview matches all elements based on the given element name. Parameter elementString is an element used for search. The tag name pointing to the DOM node. Example description: Find a DIV element. HTML code:
DIV1
DIV2
SPANjQuery code: $("div"); Result: [
DIV1
,
DIV2
].class Return value: Array.class Overview Matches elements according to the given class. Parameter classString is a class to search for. An element can have multiple classes, and it can be matched as long as one of them matches. Example description: Find all elements whose class is "myClass". HTML code:
, span class="myClass" ] selector1, selector2,selectorN return value:Arrayselector1,selector2,selectorN Overview Merge the elements matched by each selector and return them together. You can specify as many selectors as you like and combine matching elements into a single result. Parameters selector1Selector A valid selector selector2Selector Another valid selector selectorN (optional) Selector Any number of valid selectors Example description: Find elements matching any class. HTML code:
div
p class="myClass"
span
p class="notMyClass"
jQuery code: $("div,span,p.myClass") Result: [
div
,
p class="myClass"
, span ]
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn