Difference between document.getElementById and document.getElementsByClassName

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

In particular why does document.getElementsById work here

add padding
4条回答
  •  温柔的废话
    2020-12-09 14:34

    getElementById returns a single DOM element whose ID matches your query. getElementsByClassName returns an HtmlCollection - an array-like structure containing the DOM elements that matched your query. You have to iterate through each element in the array to apply your style.

提交回复
热议问题