Reputation: 150
I am trying to create a hyperlink to a facebook webpage within a message bar on my website. Here is my code
var str = "Check us out on facebook";
var result = str.link("https://www.facebook.com/pages/");
$( "#message-bar" ).click(
function() {
$("#message-form").toggle();
if($("#message" ).text() == "Thanks for stopping by mysite.ca!"){
$("#message" ).text(result)
}else{
$("#message-bar").hide();
}
});
Currently after you click the message bar once, instead of displaying the hyperlink it displays the HTML code https://www.facebook.com/pages/"> Check us out on facebook! . So my question is what should I fix to make the actual link appear instead of the code. I've been playing around/ researching the .innerHTML tag although cannot find a working solution. Any input would be apprciated, thanks.
Upvotes: 0
Views: 92
Reputation: 2154
Try this
var str = "Check us out on facebook";
var result = str.link("https://www.facebook.com/pages/");
$( "#message-bar" ).click(
function() {
$("#message-form").toggle();
if($("#message" ).text() == "Thanks for stopping by mysite.ca!"){
$("#message" ).html(result)
}else{
$("#message-bar").hide();
}
});
Upvotes: 2
Reputation: 888107
If you want to put HTML in an element, you should call html()
, not text()
.
Upvotes: 2