jQuery: how to change tag name?

前端 未结 17 948
無奈伤痛
無奈伤痛 2020-11-28 07:37

jQuery: how to change tag name?

For example:


    $1

I need

$1
<
17条回答
  •  猫巷女王i
    2020-11-28 08:27

    You can replace any HTML markup by using jQuery's .replaceWith() method.

    example: http://jsfiddle.net/JHmaV/

    Ref.: .replaceWith

    If you want to keep the existing markup, you could use code like this:

    $('#target').replaceWith('' + $('#target').html() +'')
    

提交回复
热议问题