Arnold wanna be Arnold wanna be -4 years ago 117
Javascript Question

Javascript : How can i add "×" in a button using javascript

I have a java script code that when i click submit button it will add list in my List items. but i want my list to have and "X" button or specifically "×" for deleting purpose. my code goes like this :

const closeBtn = document.createElement('button');

closeBtn.className = "closeBtn";

closeBtn.type = "button";

closeBtn.textContent = "×";


But instead of getting the X button i want, i get a button like this:

this

Answer Source

First use × and not $times;.

Second, use .innerHTML and not textContent.

const closeBtn = document.createElement('button');
closeBtn.className = "closeBtn";
closeBtn.type = "button";
closeBtn.innerHTML = "×" //String.fromCharCode("×");

document.querySelector('.content').append(closeBtn)
.closeBtn{
  font-size: 20px;
}
<div class="content"></div>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download