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.


    Friday, August 5, 2016 3:15 PM


  • 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>
    <script src="https://code.jquery.com/jquery-2.2.4.js"></script>
      $(document).ready(function() {
        $("#left_panel_line1").html("Line1" + " <br/> " + "Line 2");
      <div id="left_panel_line1"></div>

    Working Demo

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