Difference between document.getElementById and document.getElementsByClassName

后端 未结 4 1401
闹比i
闹比i 2020-12-09 14:15

In particular why does document.getElementsById work here

add padding
4条回答
  •  轮回少年
    2020-12-09 14:40

    document.getElementById("move") returns html element
    
    document.getElementsByClassName("move") returns html collection
    

    style is a property of html element hence, works fine with getElementById

    For reference -

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

    https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById

提交回复
热议问题