Javascript: how to add < as text of label html Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Javascript: how to add < as text of label html without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I have a label, and i change the text in this label using this code:

let label = document.getElementById("resultLabel")
label.innerHTML = stringResult;

where stringResult is a string.

It works, but if the string contains “<” the text is truncated at that point: for example if the string is “a<b” only “a” will be shown.

How can I insert a string containing “<” as the text of an HTML label?

Answer

How about using .textContent?

let label = document.getElementById("resultLabel");
label.textContent = stringResult;
We are here to answer your question about Javascript: how to add < as text of label html - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji