简体   繁体   中英

how do i put br in javascript .text

How do i put <br> inside my text? I tried putting <br> but it doesn't work--it just displays the literal text <br> on screen

Here is what I am trying to do:

$('#win').text(winner+' <br /> '+'stars'+'  <br />  '+'earned'+' Completion time'+' '+ counter +' seconds');

You are trying to add an HTML tag in text, but you want to see the rendered result! text will escape the HTML characters. If you want to render the HTML, then replace $('#win').text() with $('#win').html() eg :

 $('#win').html(winner+' <br /> '+'stars'+'  <br />  '+'earned'+' Completion time'+' '+ counter +' seconds');

see jQuery text
see jQuery html

这将帮助您使用$('#win').html()而不是$('#win').text()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM