Javascript 将图标附加到按钮
我有一个按钮,我想在其中插入一个带有JavaScript的图标:Javascript 将图标附加到按钮,javascript,html,Javascript,Html,我有一个按钮,我想在其中插入一个带有JavaScript的图标: <button id="chat5" onclick="actualizarIdChat('{{ elemento.pk }}')" class="btn btn-secondary" style="background-color: maroon; border-color: transparent;border-radius: 15px;height: 60px;margin: 10px 0px 10px 0px;wid
<button id="chat5" onclick="actualizarIdChat('{{ elemento.pk }}')" class="btn btn-secondary" style="background-color: maroon; border-color: transparent;border-radius: 15px;height: 60px;margin: 10px 0px 10px 0px;width: 90%;" type="button">
<img class="border rounded-circle" style="width: 50px;height: 50px;border-color: transparent;" src="{{ elemento.producto.info_producto.contenido_multimedia.0.contenido_url }}">
{{ elemento.producto.info_producto.nombre }}
</button>
{{elemento.producto.info_producto.nombre}
这是我定义的使其工作的代码,但它没有任何作用
var idChat = 'chat5';
var icon = document.createElement("div");
icon.innerHTML = '<i class="fa fa-envelope"></i>';
document.getElementById(idChat).appendChild(icon);
var idChat='chat5';
var icon=document.createElement(“div”);
icon.innerHTML='';
document.getElementById(idChat).appendChild(图标);
我该怎么做呢?更新javascript部分,它看起来像:
var buttonElement = document.getElementById("chat5");
buttonElement.innerHTML = buttonElement.innerHTML + '<i class="fa fa-envelope"></i>';
var buttonElement=document.getElementById(“chat5”);
buttonElement.innerHTML=buttonElement.innerHTML+“”;
它将起作用可能重复您可能希望像创建div一样创建元素并将其附加到div中