locked
how to force new line for a div.text() with jquery RRS feed

  • Question

  • User1868852945 posted

    With jquery I am appending to the text of my div with the code below and I want the appended text to appear on a new line.  I thought the "\a" would do this.

    $("#left_panel_line1").text($("#left_panel_line1").text() + " \a " + $("#left_panel_line1").data("capture_date"));

    This just makes an "a" appear within the changed text.  Is there some control character I can use to accomplish this?  

    I have also tried <br /> and <p> but similar results.

    I do not want to solve this with additional divs because I need this capability in many places in many pages.

    Thanks.

    Friday, August 5, 2016 3:15 PM

Answers

  • User2103319870 posted

    <br/> should work. But instead of assigning value to text assign the value to html

    $("#left_panel_line1").html($("#left_panel_line1").text() + " \a " + $("#left_panel_line1").data("capture_date"));

    Sample code I tried

    <!DOCTYPE html>
    <html>
    <head>
    <script src="https://code.jquery.com/jquery-2.2.4.js"></script>
     <script>
      $(document).ready(function() {
        $("#left_panel_line1").html("Line1" + " <br/> " + "Line 2");
      });
      </script>
    </head>
    <body>
      <div id="left_panel_line1"></div>
    </body>
    </html>

    Working Demo

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 5, 2016 3:37 PM