How can I change HTML attribute names with jQuery?

后端 未结 7 1416
無奈伤痛
無奈伤痛 2020-11-30 06:51

I would like to change all the names of the attributes where class=\"testingCase\" throughout all my whole html document.

e.g. Change:

&         


        
7条回答
  •  暖寄归人
    2020-11-30 07:02

    One liner

    $('selector').replaceWith($('selector')[0].outerHTML.replace("oldName=","newName="));
    

    worked great for me when I needed to strip a prefix from all of my attributes

    $('selector').replaceWith($('selector')[0].outerHTML.(/prefix\-/g,""));
    

提交回复
热议问题