we have a chatbot who prints replies using the jQuery
$('<div class="message message-new"><figure class="avatar"><img src="images/icon" /></figure>' + reply + '</div>').appendTo($('.mCSB_container')).addClass('new');
Sometimes the reply variable can contain links, and some of them are very long so we have been trying to hyperlink them, we tried to add an href
to the source of the replies
But the jQuery just doesn't print it, not even the hyperlink text, it just completely ignored
if the input from the back-end is
Hi <a href="www.google.com" click here /a>
It just prints "Hi"
Can somebody please guide us on how we can enable hyperlinks by making changes in the source text to the reply variable or any other way
<!DOCTYPE html>
<html>
<head>
<script src="jquery.min.js"></script>
<script>
$(document).ready(function() {
$("button").click(function() {
reply = 'Hi! What can I help you with?<p><a href="www.google.com">google</a></p> ';
$('<div class="message message-new"><figure class="avatar"><img src="avatars1.githubusercontent.com/u/6422482?v=3&s=400"; /></figure>' + reply + '</div>').appendTo($('.mCSB_container')).addClass('new');
});
});
</script>
</head>
<body>
<p>Top</p>
<div class="mCSB_container">
test
</div>
<button>Add New </button>
</body>
</html>
$('<a>', {
href: 'mylink.com',
html: 'mytext'
})
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.