简体   繁体   中英

Appending a style tag with jQuery

I'm trying to build a basic chatroom on my site using socket.io. I have the base functionality working, but I want to bold one of my input fields. I've tried variations on

$('#messages').append($('<li>').text('<strong>'+msg.user+': </strong>'+msg.message));

and it just ends up appending, literally <strong> . How should I format this to actually bold 'msg.user'?

代替使用.text ,尝试使用.html

您可以使用.html()代替.text()

$("#messages").append( $("<div>").html("<strong>" + msg.user + "</strong>" + msg.message));

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