Jefferson
Jefferson

Reputation: 93

javascript html label displaying incorrect values

I have a string that coming from a database something like this test&nbsp;(test<sup>&reg;</sup>) that I would like to display in a label. I try to parse the text but it displays just the last value in the string. I did try to set the innerHTML value to the string and that didn't display any value.

Is there any other way to fix this?

    strHTML = $.parseHTML('test&nbsp;(test<sup>&reg;</sup>)');
    var Name = "";
    $.each(strHTML, function (i, el) {
      Name = el.wholeText;
    });
    $(".lbl-drug").text(Name);

Upvotes: 0

Views: 89

Answers (1)

silentw
silentw

Reputation: 4885

strHTML = $.parseHTML('test&nbsp;(test<sup>&reg;</sup>)');
$(".lbl-drug").html(strHTML);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label class="lbl-drug"></label>

Upvotes: 2

Related Questions