Uncaught TypeError: Cannot call method 'hasAttribute' of undefined
I am trying to check if buttons has name attribute or not.The Following
line is giving result correctly.
alert(course_view_buttons[30].hasAttribute("name"));
But the following code is giving an error like this-
"Uncaught TypeError: Cannot call method 'hasAttribute' of undefined "
The full code is here-
var course_view_buttons = document.getElementsByTagName("button");
alert(course_view_buttons.length);
var a=0;
for (x=0;x<=course_view_buttons.length;x++){
if(course_view_buttons[x].hasAttribute("name");){
a++;
}
}
alert(a);
Please help me if anyone can.I am stuck in this for 4-5 hours. Thanks in
advance.
No comments:
Post a Comment