简体   繁体   中英

Can I append Icons in JavaScript as text content

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM