Can I append Icons in JavaScript as text content

Viewed 205

I have button which is created using JavaScript

const deleteButton = document.createElement('button')

I want to append the delete/trash Icon, the below code is working

deleteButton.classList.add('far', 'fa-trash-alt')

but the Thing is I only want to append the icon only, rather then a button, can anyone know how we can do it, but catch is it should be button because the button has assigned to function

1 Answers

You can create a span instead a button, try this:

let deleteSpan = document.createElement('span');
deleteSpan.classList.add('far', 'fa-trash-alt')

Related