Reputation: 1851
I am working on asp.net mvc. I have a javascript variable like,
var note="<strong><em><span style='color:#ed1c24;'>Hai</span></em><span style='color:#ed1c24;'>Welcome</span></strong> ";
I need to display as a html with in the label so i tried it like,
$('#lblNote').html(note);
but it doesnt render the html content and it shows the html tags as it is like,
<label id="lblNote"><strong><em><span style=""color:#ed1c24;"">
Hai</span></em><span style=""color:#ed1c24;"">
Welcome</span></strong> </label>
please guide me.
Upvotes: 0
Views: 1600
Reputation: 144669
There are two syntax errors in your code, 1. change the wrapping quotes to single quotes or escape them 2. and remove the line-breaks or concatenate the strings.
var note = '<strong><em><span style="color:#ed1c24;">Hai</span></em><span style="color:#ed1c24;">Welcome</span></strong>';
You should replace the characters:
$('#lblNote').html(note.replace(/</g, '<').replace(/>/g, '>'))
Upvotes: 2
Reputation: 2543
Format your string properly. note should be
var note="<strong><em><span style=\"color:#ed1c24;\">
Hai</span></em><span style=\"color:#ed1c24;\">
Welcome</span></strong> ";
Upvotes: 1
Reputation: 4539
Try this
var note="<strong><em><span style='color:#ed1c24;'>Hai</span></em><span style='color:#ed1c24;'>
Welcome</span></strong> ";
$('#lblNote').html(note);
Upvotes: 1
Reputation: 7887
escape your double quotes like this
var note="<strong><em><span style=\"color:#ed1c24;\">
Hai</span></em><span style=\"color:#ed1c24;\">
Welcome</span></strong> ";
Upvotes: 1