Javascript for adding a custom attribute to some elements

前端 未结 4 1630
渐次进展
渐次进展 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 13:59

    You can look here how to get and set the attribute.

    https://jsfiddle.net/tuc57hbp/6/

    to get attribute you must first get the value. Then you must get it's input children using td.children[0] and set the input children attribute value using input.setAttirbute('dummy', 'value'). Then retrieve it using getAttribute('dummy').

提交回复
热议问题