0

I am creating a simple modal where I pass a string and that gets displayed as the content of the modal.

In a nutshell, I have this script:

   $("[id^='mod_']").click( function() {

      var line1    = $(this).attr("data-modaltext1");

       $('#modalid').show();
       $('#modalmessage').text(line1);

The above works as expected. But if my string I pass and picked up by data-modaltext1 is

"<p>Hello</p><p>World</p>"

It prints is as seen without the html tags working. I don't get two paragraphs. Just one string that looks exactly like

 "<p>Hello</p><p>World</p>"

Any help will be appreciated.

1
  • 1
    Change .text to .html. Commented Apr 8, 2017 at 23:20

1 Answer 1

2

Use the html method instead so it can be treated as raw html code and not just text:

$('#modalmessage').html(line1);
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome. Thanks !

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.