Reputation: 9158
I am trying to access the DIV with the id "codeDef" using
document.getElementById['codeDef']
But it returns "undefined".What am I doing wrong here?
Here is the HTML snippet :
<div class="section">
<div class="box">
<form method="post" name="exam-company-input-form" action="./">
<table>
<tbody><tr>
<td style="width:150px;padding-left:20px">
Exam Code
</td>
<td style="width:150px;padding-left:20px"><input type="text" maxlength="10" style="width:100%" value="" name="code" onkeyup="javascript:checkExamCode();"></td><td><div id="codeDef">code def</div></td>
</tr>
<tr>
<td style="width:150px;padding-left:20px">
Orca Code
</td>
<td style="width:150px;padding-left:20px"><input type="text" maxlength="10" style="width:100%" value="" name="srycd" onkeyup="javascript:checkOrcaCode();"></td><td id="orcaDef">orca def</td>
</tr>
<tr>
<td style="text-align:center" colspan="3">
<button style="opacity: 1; margin-right: 15px;" onclick="javascript:ResetForm('exam-company-input-form');" class="blue" type="button"><span>リセット</span>
</button><button style="opacity: 1;" onclick="javascript:SubmitForm('exam-company-input-form');" class="blue" type="button"><span>登 録</span>
</button></td></tr>
</tbody></table>
<input type="hidden" value="master_exam-company-input-do" name="pid">
</form>
</div>
</div>
Upvotes: 0
Views: 1489
Reputation: 160833
It should be document.getElementById('codeDef')
.
If you use []
, it means you want to get the property codeDef
of the Function document.getElementId
, and obviously, there is no such property, so you will get undefined
.
Upvotes: 3
Reputation: 55271
It's a function, try
document.getElementById('codeDef')
Instead of
document.getElementById['codeDef']
Upvotes: 1