AndrewS AndrewS - 1 month ago 14
HTML Question

How to clone any data from a widget with Jquery?

I use a social comments widget for my wesbite, and i want to clone some data from the widget and use it as I want in my template.

To clone the data I use this jQuery code:

var $button = $('#hypercomments_widget').clone(true);
$('.image_01').html($button);


But it does't work.

Please, if this is possible to get done, help me.

Widget code in side HTML:

<div id="hypercomments_widget"></div>
<script type="text/javascript">
_hcwp = window._hcwp || [];
_hcwp.push({widget:"Stream", widget_id: xxxxx});
(function() {
if("HC_LOAD_INIT" in window)return;
HC_LOAD_INIT = true;
var lang = (navigator.language || navigator.systemLanguage || navigator.userLanguage || "en").substr(0, 2).toLowerCase();
var hcc = document.createElement("script"); hcc.type = "text/javascript"; hcc.async = true;
hcc.src = ("https:" == document.location.protocol ? "https" : "http")+"://w.hypercomments.com/widget/hc/82481/"+lang+"/widget.js";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hcc, s.nextSibling);
})();
</script>


JSFIDDLE

Answer

Because you should wait after your plugin loaded fully try to setTimeout() 3 seconds (tested).

see https://jsfiddle.net/tgza3x4o/4/

so this is a working solution

setTimeout(function(){
    var $button = $('#hypercomments_widget').clone(true);
    $('.image_01').html($button);
    },3000);//3 seconds