0

I am trying to find an input with a class of blocked and remove the disabled attribute. This is what I have...

<input id="test" class="blocked" type="text" disabled="disabled" value="Some Value">
<script>
    document.getElementsByClassName("blocked").removeAttribute("disabled");
</script>

This needs to be done using Javascript and not jQuery, why is it not working as expected?

fightstarr20
  • 11,682
  • 40
  • 154
  • 278

1 Answers1

2

You have to write it like below,

document.getElementsByClassName("blocked")[0].removeAttribute("disabled");

Since getElementsByClassName() will return a node list, Technically a [object HTMLCollection]. So You have to access the first element from that collection and invoke the functions that you want.

Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130