Home > OS >  replace div content jquery and show fontawesome icon
replace div content jquery and show fontawesome icon

Time:10-16

I am writing a method to show fontawesome icons so the user can select one. When selected I want to change the content of a div with the name selected and also show the icon.

My jQuery function is

function changeSelected(boxName,name){
            var newText = "you have chosen "   name   " - <i class='fa-solid fa-"   name   "' aria-hidden='true'></i>";
            $('#'   boxName  'Chosen').text(newText);
          }

My problem is that it is showing the content with the code not the icon

output sample

Is there any way to show the icon?

CodePudding user response:

Use .html(newText) instead of .text(newText)

  • Related