我有一个脚本应该找到类 li
的元素 (active
) 并将其替换为
product.type-product.post-1922.status-publish.instock.product_cat-globallogic.product_cat-buklety.has-post-thumbnail.shipping-taxable.product-type-simple
:
<script>
var actives = document.getElementsByClassName("active");
actives.className = actives.className.replace("active", "product.type-product.post-1922.status-publish.instock.product_cat-globallogic.product_cat-buklety.has-post-thumbnail.shipping-taxable.product-type-simple");
</script>
我收到错误 Uncaught TypeError: Cannot read property 'replace' of undefined
。虽然我有一个类 active 的元素:
<li class="active">
//code
</li>
为什么我有这个错误?