how to append a css class to an element by javascript?

前端 未结 7 1945
慢半拍i
慢半拍i 2020-12-14 14:09

Suppose a HTML element\'s id is known, so the element can be refereced using:

document.getElementById(element_id);

Does a nati

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-14 14:58

    classList is a convenient alternative to accessing an element's list of classes.. see http://developer.mozilla.org/en-US/docs/Web/API/Element.classList.

    Not supported in IE < 10

提交回复
热议问题