Javascript for adding a custom attribute to some elements

前端 未结 4 1633
渐次进展
渐次进展 2021-02-01 13:22

Given a section of HTML, can I selectively pick some types of elements (e.g., input) and add a custom attribute using JavaScript? I would also need to remove this attribute if i

4条回答
  •  故里飘歌
    2021-02-01 14:06

    Accessing HTML attributes using the DOM

    element.hasAttribute('foo');
    element.getAttribute('foo');
    element.setAttribute('foo', value);
    element.removeAttribute('foo');
    

提交回复
热议问题