Niveditha Karmegam
Niveditha Karmegam

Reputation: 740

Why cant we print a variable with html names included in it?

I am trying to learn ReactJS.

I have a html selections option as
<option value="navigate">Navigate to &lt;URL&gt; </option>

and I have obtained the selected text in my script

let type = document.getElementById ('stepType').options[document.getElementById('stepType').selectedIndex].text;

when i console.log(type) i am getting "Navigate to <URL>"

but when i try to update my div's inner html, all that is getting printed is "Navigate to "

Thanks for putting up with my stupid question, but I would really like to know what is happening underneath, since i know let type = "Navigate to &lt;URL&gt;" would work.

Upvotes: 1

Views: 46

Answers (1)

Giang Le
Giang Le

Reputation: 7089

to avoid XXS attach React will render text. If you want to render html use

<div dangerouslySetInnerHTML={{__html: "Navigate to &lt;URL&gt;"}}/>

Upvotes: 1

Related Questions