Change node type

前端 未结 4 1648
广开言路
广开言路 2021-01-05 03:44

Using jQuery, is it possible to change all matched elements to a different type?

For example, can I select all a tags, $(\"a\"), and change

4条回答
  •  灰色年华
    2021-01-05 04:35

    Changing an A element to an INPUT element isn't changing the type, it is changing the tagName. According to the DOM 2 Core specification, an element's tagName is readonly, so no, you can't set it.

    However, you can replace an element with a different element, provided it is valid in the DOM.

提交回复
热议问题