I'm trying to iterate through an array of textareas on my page with ClassName TextInput
and change their values ( innerHTML
). The function I wrote is as follows-
function init() {
var TextInput[] = document.getElementByClassName("TextInput"); //line 12
for(var i = 0; i < TextInput.length; i++) {
TextInput[i].innerHTML = "N/A";
}
}
Firefox 18.0.2's debug console says SyntaxError: missing ; before statement
SyntaxError: missing ; before statement
on line 12.
What is wrong with my code and how can I achieve what I'm trying to do?
You don't need to add []
, just
var TextInput = document.getElementByClassName("TextInput"); //line 12
Edit: And as @Benjamin pointed out, the function name is missing a s
.
This should work:
var TextInput = document.getElementsByClassName("TextInput"); //line 12
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.