1

nowadays i am upto java script, jquery etc. i am facing little problem.

i am writing a text message inside CASE block , it's a long string when displayed:

Record has been saved successfully Note: If head already exists for the concerned department than your head selection would not have been saved. 

but i want it like this:

Record has been saved successfully 
Note: If head already exists for selected department 
than your head selected would not have been saved.

function ShowMsg() {
        var MessageStatus = $("#HiddenFieldSetMessage").val();
        switch (MessageStatus) {
            case 'SavedButHeadMightExist':
                $("#Msg").text("Record has been saved successfully Note: If head already exists for the concerned department than your head selection would not have been saved");
                $("#ModalHeader").text("Success");
                break;
            case 'NotSaved':
                $("#Msg").text("Record not inserted");
                $("#ModalHeader").text("Error");
                break;
    }
    </script>
Aristos
  • 66,005
  • 16
  • 114
  • 150
user3518032
  • 423
  • 8
  • 25

3 Answers3

3

You could use newlines, but those aren't really shown, what you really want is probably just break tags

$("#Msg").html("Record has been saved successfully<br />" +
               "Note: If head already exists for the concerned department<br />" +
               "than your head selection would not have been saved");

Note that you have to change the method from text() to html()

adeneo
  • 312,895
  • 29
  • 395
  • 388
1

you need to use <br/> for line break. and use html instead of text

text: it is used for text only no html is allowed
html: it allow html tags also

You can find difference between these two here

  1. What is the difference between jQuery: text() and html() ?
Community
  • 1
  • 1
शेखर
  • 17,412
  • 13
  • 61
  • 117
0

Change .text to .html

$('#Msg').html('line1<br>line2');

OR

var escaped = $('<div>').text(stringDisplay).text();
$('#Msg').html(escaped.replace(/\n/g, '<br />'));
user3244721
  • 714
  • 2
  • 11
  • 29