Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含 html 元素的字符串,如下所示
var elements = "<div class='instance' id=''><h1></h1></div>";
如何使用它才能做到这样
$('instance').prop('id',5); $('instance h1').html('hello all');
您可以将其直接加载到新的 jQuery 对象中:
$(elements).find("h1").html("Hello All").appendTo("body");
此外,5不是有效的id- 请不要在id值的开头使用数字。
5
id