i am setting a text of a h4 through java script what i want to do is add new line here's the code
$("#description").text("for CCAET and has received significant international scientific recognition. <br /> \n Dr. Armogan has also been responsible for many surgical firsts in retina and cataract management.");
now i tried it with multiple solutions but still not working here's another one
$("#description").text("or CCAET and has received significant international scientific recognition.Dr. Armogan has also been responsible for many surgical firsts in retina and cataract management."+
"abc"+
"def");
any help?
尝试$("#description").html(...)
代替$("#description").text(...)
。
Use html instead of text . This because html will render the HTML code. The text method will only insert and escape all HTML content. Ref. https://api.jquery.com/html/
$(document).ready(function() { var content = "This<br/>is<br/>modified<br/>text"; $('h4#one').html(content); $('h4#two').text(content); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <h4 id="one"> This is initial text </h4> <h4 id="two"> This is initial text </h4>
使用html()函数将原始html放在元素中
$("#description").html("for CCAET and has received significant international scientific recognition. <br /> \n Dr. Armogan has also been responsible for many surgical firsts in retina and cataract management.");
use html function with
tag.it will preserve your raw html .
$("#description").html("<pre>for CCAET and has received significant international scientific recognition. <br /> \n Dr. Armogan has also been responsible for many surgical firsts in retina and cataract management.</pre>");
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.