最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Cannot read property 'style' of null - Stack Overflow

programmeradmin0浏览0评论

For some strange reason I get a weird error.

I have an element (which I'd defined with PHP) that eventuly looks like this:

    <span id="l_area_1_5" style="display: inline; ">

    ...some html inputs and stuff....

    </span>

Which I am certain by Inspect Element of the Chrome.

Now when I try to address to it programaticly with this:

document.getElementById("1_area_1_5").style.display = 'none';

I get the Cannot read property 'style' of null error.

I have no idea what the hell that's supposed to mean, any help?

For some strange reason I get a weird error.

I have an element (which I'd defined with PHP) that eventuly looks like this:

    <span id="l_area_1_5" style="display: inline; ">

    ...some html inputs and stuff....

    </span>

Which I am certain by Inspect Element of the Chrome.

Now when I try to address to it programaticly with this:

document.getElementById("1_area_1_5").style.display = 'none';

I get the Cannot read property 'style' of null error.

I have no idea what the hell that's supposed to mean, any help?

Share Improve this question edited Nov 13, 2011 at 18:41 Ash Burlaczenko 25.5k16 gold badges69 silver badges101 bronze badges asked Nov 13, 2011 at 18:35 eric.itzhakeric.itzhak 16.1k27 gold badges94 silver badges146 bronze badges 1
  • maybe, The problem is that you are calling the javascript function before loading the actual HTML content.. – T.Todua Commented Sep 25, 2013 at 20:55
Add a comment  | 

1 Answer 1

Reset to default 13

The error means that the element doesn't exist. It's because you have a typo. You wrote 1 instead of l.

l_area_1_5
1_area_1_5
^
发布评论

评论列表(0)

  1. 暂无评论