I am trying to achieve at below
var a = "how are you. <br> fine";
var b = "how are you, <br> fine";
alert(a);
alert(b);
Output should be
How are you
fine
But It gives me
how are you. <br> fine
how are you, <br> fine
> < and   are in my string
How can I decode this html in alert message of javascript
Ty to use \\n
in place of <br>
like,
var b = "how are you, \n fine";
alert(b);
To show HTML content
you can try jquery-alert
Try this...
var text = '<p>name</p><p><span style="font-size:xx-small;">ajde</span></p><p><em>da</em></p>';
var decoded = $('<div/>').html(text).text();
alert(decoded);
Edit: As Rohan Kumar has suggested above, I don't think it is possible to render HTML inside an alert box (which is what you are implying in your question). but rather you would need to do something like below, ie use replace or even better look into using a modal dialogue
var text = 'how are you, <br> fine';
var text = text.replace('<br>','\n');
var decoded = $('<div/>').html(text).text();
alert(decoded);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.