gpt4 book ai didi

javascript - css nth-child nth-last-of-type with javascript – 没有jquery

转载 作者:行者123 更新时间:2023-11-29 10:46:34 26 4
gpt4 key购买 nike

是否有可能仅使用纯 javascript 向 nth-child() 和 nth-last-of-type() 提出上诉(无需 jquery)?我想在很大程度上避免使用 jquery。

最佳答案

使用document.querySelectorAll .

例如

var elements = document.querySelectorAll('div:nth-child(5)');

文档.querySelectorAll

Summary

Returns a list of the elements within the document (using depth-firstpre-order traversal of the document's nodes) that match the specifiedgroup of selectors. The object returned is a NodeList.

Syntax

elementList = document.querySelectorAll(selectors);

where

elementList is a non-live NodeList of element objects.

selectors is a string containing one or more CSS selectors separated by commas.

The returned NodeList will contain all the elements in the documentthat are matched by any of the specified selectors. If the selectorsstring contains a CSS pseudo-element, the returned elementList will beempty.

关于javascript - css nth-child nth-last-of-type with javascript – 没有jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18586049/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com