在Javascript中这个getElementsByClassName调用有什么问题? [英] What is wrong with this getElementsByClassName call in Javascript?

查看:161
本文介绍了在Javascript中这个getElementsByClassName调用有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问div的宽度以放入cookie。这是div:

I am trying to access the width of a div to put in a cookie. This is the div:

 <div class="tab_panel" style="width:600px">

这是唯一具有此类名的div。不能为div指定唯一ID。这是我在事件中使用的代码来调用它但是它给出了一个错误:

It is the only div with this class name. It is not an option to specify a unique id for the div. This is the code I have been using in an event to call it but it gives an error:

 document.getElementsByClassName(tab_panel).style.width

我知道Firefox支持 getElementsByClassName ,那么我做错了什么?

I know Firefox supports getElementsByClassName, so what am I doing wrong?

推荐答案

这是一个字符串:

document.getElementsByClassName("tab_panel")[0].style.width

再见

PS这是一个数组

这篇关于在Javascript中这个getElementsByClassName调用有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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