getElementsByClass and appendChild

后端 未结 3 1288
悲哀的现实
悲哀的现实 2021-01-04 04:19

just brushing up on my javascript skills and trying to figure out why getElementsByClass isn\'t working for my code. The code is pretty simple. Upon clicking a button \"cl

3条回答
  •  醉酒成梦
    2021-01-04 05:01

    You need to update your code from

    document.getElementsByName("thistime").appendChild(first);
    

    to

    document.getElementsByClassName("thistime")[0].appendChild(first);
    

    For reference - https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName

    Working code - http://plnkr.co/edit/k8ZnPFKYKScn8iYiZQk0?p=preview

提交回复
热议问题