0

I have a "Label" control on my form which is being populated via jquery. My problem however, is I need to return my string with html tags, but my label doesn't seem to recognize html. Here's my control:

<label id="comment"></label>

And here's how I'm working with it in javascript:

var comment;
comment = $("#comment");
comment.text("<b>Please scan an <br/>item!</b>");

In the above code, the html in my string is ignored. Is there any way I can get my form to recognize the returned html tags?

Thanks

3 Answers 3

6

Use the html function :

comment.html("<b>Please scan an <br/>item!</b>");
Sign up to request clarification or add additional context in comments.

1 Comment

Specifically, the text function deliberately escapes the string so it renders correctly in html. As a result, things like <b> get converted to &lt;b&gt;
3

try comment.html("<b>Please scan an <br/>item!</b>");

You could also use document.getElementById("comment").innerHTML = "<b>Please scan an <br/>item!</b>";

Comments

0
comment.html("<b>Please scan an <br/>item!</b>");

1 Comment

It's the same problem as the question!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.