等效于Java中的类的getElementById [英] Equivalent of getElementById for Classes in Javascript

查看:37
本文介绍了等效于Java中的类的getElementById的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在制作游戏,并且试图更改整个对象类的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆