jQuery - 更改 Div ID 的值

jQuery - change value of Div ID

本文关键字:ID 的值 Div 更改 jQuery      更新时间:2023-09-26

>我有这个:

<div id="something">
content
</div>

我需要使用 jQuery 将something更改为somethingnew,因此:

<div id="somethingnew">
content
</div>

我该怎么做?我已经尝试过函数attr,但它不起作用。谢谢你的建议。

这个:

$("#something").attr("id", "somethingnew");

试试这个。

$("#something").attr("id","somethingnew");

$("#something").attr("id", "somethingnew");应该可以正常工作