Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将图标附加到按钮_Javascript_Html - Fatal编程技术网

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

我有一个按钮,我想在其中插入一个带有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;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 }}">
    &nbsp; &nbsp; &nbsp;{{ 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中