Take for example this HTML:
<td onclick="$(this).html('Wanted HTML: <br>; Unwanted HTML: <script>alert('xss')</script>')">
Click to Show</td>
As you can see, I have already escaped (using PHP) the unwanted HTML to entities. But when you click the box it executes the JavaScript.
If I change .html
to .text
, it displays the line breaks literally as well.
How can I have it show the the <br>
s as line breaks, but the <
s and >
s as literally less than and greater than signs when you click the box?