JavaScript获取没有任何库的元素类 [英] JavaScript getting an elements class without any libraries

查看:100
本文介绍了JavaScript获取没有任何库的元素类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用JavaScript获取元素的属性的值。然而在这种特殊的情况下,我没有像YUI,jQuery等图书馆的奢侈,需要坚持的基础。

I would like to get the value of the class attribute for an element using JavaScript. However in this particular situation I don't have the luxury of library such as YUI, jQuery, etc. and need to stick to the basics.

具体来说,我循环

我试过:

var colClass = el.getAttribute('class');

var colClass = el.class;

但两者似乎都不起作用。在上面的例子中, el 是从表的单元数组中设置的,例如 var el = document.getElementById('myTable' y] .cells [y];

But neither seems to be working. In the above example, el is set from cells array of a table, such as var el = document.getElementById('myTable').rows[y].cells[y];

推荐答案

也许你应该尝试

var colClass = el.className

这篇关于JavaScript获取没有任何库的元素类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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