0

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.

0

4 Answers 4

2

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>';

http://jsfiddle.net/VsGqg/


You should replace the characters:

$('#lblNote').html(note.replace(/&lt;/g, '<').replace(/&gt;/g, '>'))
Sign up to request clarification or add additional context in comments.

1 Comment

@undefined: I modify my question please have a glance on it.
1

escape your double quotes like this

var note="<strong><em><span style=\"color:#ed1c24;\">
Hai</span></em><span style=\"color:#ed1c24;\">
Welcome</span></strong> ";

1 Comment

I modify my question please have a glance on it.
1

Try this

var note="<strong><em><span style='color:#ed1c24;'>Hai</span></em><span style='color:#ed1c24;'>
Welcome</span></strong> ";

$('#lblNote').html(note);

1 Comment

:I modify my question please have a glance on it.
1

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> ";

1 Comment

I modify my question please have a glance on it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.