I need to create an Embedded Post on a page through a Click event. I am using the following function:
<body>
<div id="fb-root"></div>
<div id="myDiv"></div>
<div id="myDiv2"></div>
<script>
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/pt_BR/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div class="fb-post" data-href="https://www.facebook.com/michael/posts/046153"></div>
<script>
$(document).ready(function(){
myLink = "https://www.facebook.com/michael/posts/045847";
var embPost = '<div class="fb-post" data-href="' + myLink + '"></div>';
$("#myDiv2").append(embPost);
myLink = "https://www.facebook.com/michael/posts/045558";
document.getElementById("myButton").onclick = function() {
var embPost = '<div class="fb-post" data-href="' + myLink + '"></div>';
$("#myDiv").append(embPost);
}
});
</script>
</body>
The click of this button inserts this embPost
into #myDiv
, but does not generate embedded post , as expected, on the other hand #myDiv2
displays embPost
completely rendering.