JSLite - find nodes
If you have any questions, you are welcome to communicate in these places, and you are welcome to join the JSLite.io organization team for joint development!
find
A collection of descendant nodes (you can bring a filter selector).
$("#box").find() //⇒后代节点的集合 $("#box").find(".box") //⇒后代节点的集合,返回匹配".box" 的集合
children
Get the direct child elements of each matching element set element (can bring filter selector).
$("#box").children() //下面这种方法也可以的 CSS3 节点选择器 -_+ $("#box *")
contents
Get the child elements of each matching element collection element, including text and comment nodes.
contents() ⇒ collection
$("#box").contents()
parent
The direct parent element of each element in the object collection.
$("#box").parent()
parents
Get all the ancestor elements (excluding the root element) of each element in the object collection.
parents([selector]) ⇒ collection
$("#box").parents() $("#boxWhy").parents(".boxss")
closest
Start from the element itself, match up to the upper element step by step, and Returns the ancestor element that first matches
selector
. If thecontext
node parameter exists. Then the descendants of this node are always considered. This method is somewhat similar toparents(selector)
, but it only returns the first matching ancestor element.
$("#box").closest("div") $(document).bind("click", function(e) { console.log(e.target)//当前点击的对象 $(e.target).closest("li").css("background","red"); }); $("#boxWhy").closest(".boxss",$("#box")[0])//#boxWhy节点的父节点为:"$("#box")[0]"的子节点".boxss"
prev
Get all the previous objects of each element in the object collection (you can bring a filter selector).
$("#box").prev("div")
next
Get all the next objects of each element in the object collection (you can bring a filter selector).
$("#box").next("div")
prevAll
Get all sibling objects of this object [top] (you can bring a filter selector).
$("#box").prevAll("div")
nextAll
Get all sibling objects of this object [lower] (you can bring a filter selector).
$("#box").nextAll("div")
siblings
Get all sibling objects of this object [other] (can bring filter selector).
$("#box").siblings()
slice
Method to extract from array. Start from start if end is indicated. Extract elements that do not contain the end position.
slice(start, [end]) ⇒ array
$("div").slice(3) //返回数组中第三个(包含第三个)之后的所有元素 $("div").slice(3,5) //返回数组 3-5之间的元素
add
Add elements to the matching collection of
JSLite
objects
$("#box").siblings()