html label inserting newline

后端 未结 3 824
长情又很酷
长情又很酷 2021-02-14 13:32

I\'m trying to set some text to a label dynamically using jQuery. But i can\'t get the
or \\n to render and give me new lines. It all shows

相关标签:
3条回答
  • 2021-02-14 14:14

    Try this instead:

    $('#myLabel')
        .html('this is my first line<br/>This should be my second line.');
    
    0 讨论(0)
  • 2021-02-14 14:22

    text() will escape any html code, so instead use html()

    $("#myLabel").html("This is my first line <br /> This should be my second line.");
    
    0 讨论(0)
  • 2021-02-14 14:32

    The problem is that .text() will ignore your html. You should use .html(), soy u can put whatever html you want inside an element. So you'd have:

    $('#myLabel').html('This is my first line <br/> This should be my second line.');
    

    Hope this helps. Cheers

    0 讨论(0)
提交回复
热议问题