等效于Java中的类的getElementById [英] Equivalent of getElementById for Classes in Javascript
问题描述
我目前正在制作游戏,并且试图更改整个对象类的CSS值.对于单个ID,我将使用 document.getElementById("idHere")
,但是我需要类似 document.getElementByClass("classHere")
的名称.谢谢!
仅存在 document.getElementsByClassName("myClass")
,它返回具有该HTML类的所有元素的数组./p>
如果您使用的是jQuery,则可以使用 $(.myClass")
完成,它将返回该类的所有元素的集合.
I'm currently making a game, and I'm trying to change the CSS values of a whole class of objects. For a single ID, I would use, document.getElementById("idHere")
, but I need something like document.getElementByClass("classHere")
. Thanks!
There is simply document.getElementsByClassName("myClass")
, which returns an array of all the elements with that HTML class.
If you're using jQuery, you can do it with $(".myClass")
, which will return a collection of all of the elements with that class.
这篇关于等效于Java中的类的getElementById的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!