I have a paragraph, which I would like to edit using javascript prompt
function.
All work ok while I didn't enter <
or >
. They looks good in html, but when I would like to edit them again, I see ugly >
and <
The issues can be easy reproduced via following scenario:
- press Edit-button,
- Enter string
<<<>>>
. - press Edit-button again.
You will see ugly prompt symbols in dialog.
In prompt-dialog ugly un-escaped symbols appear.
In fact before passing innerHTML to prompt function I should un-escape characters, how could this be done?
Part of my code following:
<script type="text/javascript">
function edit()
{
str = document.getElementById('par').innerHTML;
str = prompt(str, str);
document.getElementById('par').innerHTML = str;
}
</script>
<p id="par">aaa</p>
<input type="button" onclick="edit()" value="Edit" />
I prefer API-function instead of manual replacing gt;
an <
.
jquery solution is also interseting for me.
Thanks!