1

I have a bootstrap modal dialog whose content is being dynamically set in button click based on what is selected by the user. I would like to display the selection as bold. However, when rendered it displays the bold tags (less than b greater than) and (less than forward slash b greater than) instead of text being bold.

 JS
 $("#SubmitBtn").click(function () {
     var dropDownText = $("#DSLDropDownList option:selected").text();

     $('#ConfirmationDialog').modal('show');

     $('#ConfirmationMessage').text('You selected ' + '<b>' + dropDownText + '</b>'
 )
 -----------------------------------------------------------------------
 HTML
 <button type="button" id="SubmitBtn" class="btn btn-primary">Submit</button>

 <div id="ConfirmationDialog" class="modal fade" role="dialog">
      <div class="modal-dialog">
           <div class="modal-content">
                  <div id="ConfirmationMessage"></div>
           </div>
      </div>
 </div>

I would like it to display, You Selected followed by value of dropDownText in bold font. Instead it displays bold tags.

2 Answers 2

2

.text() renders given input as plaintext

Use .html() instead of .text():

$('#ConfirmationMessage').html('You selected ' + '<b>' + dropDownText + '</b>');

Example

var dropDownText = "foo";

$('#ConfirmationMessage').html('You selected ' + '<b>' + dropDownText + '</b>');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>

<span id="ConfirmationMessage"></span>

Sign up to request clarification or add additional context in comments.

1 Comment

Valar morghulis :)
1
$("#ConfirmationMessage").html("<b>You selected " + dropDownText + " </b>");

3 Comments

No need for duplicate answers please.
don't forget the close the parenthesis
first answer won't work cause the parenthesis must close and a semicolon

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.