getelementbyclassname instead of getelementbyid is not working

后端 未结 1 841
甜味超标
甜味超标 2021-01-27 08:48

I have read many times that you can NOW get getElementsByClassName. This below works fine IF I replace ClassName by Id, but using the word ClassName does not work. Anyone know w

1条回答
  •  难免孤独
    2021-01-27 09:21

    The function is called getElementsByClassName. Plural. It returns not an element, but an array of all the elements that have the class name.

    So even if the array consists of only one item, even there is only one element in the array, you still need to index it.

     x[0].disabled=true
    

    instead of

     x.disabled=true
    

    Fiddle

    0 讨论(0)
提交回复
热议问题