trouble with a javascript Cannot read property 'value' of

Posted by Stanislas Piotrowski on Stack Overflow See other posts from Stack Overflow or by Stanislas Piotrowski
Published on 2012-10-05T09:17:10Z Indexed on 2012/10/05 9:37 UTC
Read the original article Hit count: 144

Filed under:
|

I've done a function but I do not understand why, a part of it does not work.

Actualy I use the methode using className and Id.

Here is the part of the code:

 var items = new Array();
 var itemCount = document.getElementsByClassName("items");

 for(var i = 0; i < itemCount.length; i++)
 {
     items[i] = document.getElementById("p"+(i+1)).value;
 }

 return items;
 }

And in jsfiddle the html part that show that this Id exist.

So it should not return to me this errors:

Uncaught TypeError: Cannot read property 'value' of null fiddle.jshell.net:402

the concerned line is the following:

items[i] = document.getElementById("p"+(i+1)).value;

http://jsfiddle.net/Wt4qd/

Kind Regards SP.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about getelementbyid