How to run javascript functions after replacing code
Hi,
I need to add several times a chunk of code that's hidden after being changed.
I created some functions to hide part of the code, remove it all and sort those chunks,
combining Connect lists with tabs with Hide and Accordion.
Initailly that function was working but when i added the part to replace existing code with the chunks that i want to show, that function stop working.
The code that repalce the exixting one is this:
-
var template = '<ul id="sortable-' + j + '" class="connectedSortable ui-helper-reset" style="height:auto;">';
var end = '</ul>';
$("div").find('ul#sortable-' + j).replaceWith(template + panels + end);
panels is the result of this fuinction called several times
- function chunk(NewData){
- var bar ='<nvd3-multi-bar-chart data="#6" id="#7" height="400" showXAxis="true" reduceXTicks="true" showYAxis="true" showLegend="true" showControls="true" tooltips="true"><svg></svg></nvd3-multi-bar-chart>';
- var pie = '<nvd3-pie-chart data="#6" id="#7" height="300" width="500" x="xFunction()" y="yFunction()" showLabels="true" pieLabelsOutside="true" showValues="true" labelType="percent" showLegend="true" tooltips="true"><svg></svg></nvd3-pie-chart>';
- var line = '<nvd3-line-with-focus-chart data="#6" id="#7" height="400" showLegend="true"></nvd3-line-with-focus-chart>';
- var table = '';
- var $clonedDiv = $('#hiddenChart').clone();
-
- $clonedDiv.find("div[id='#1']").attr("id", NewData[1]);
- $clonedDiv.find("div[id='#2']").attr("id", NewData[2]);
- $clonedDiv.find("i[id='#3']").attr("id", NewData[3]);
- $clonedDiv.find("i[id='#4']").attr("id", NewData[4]);
-
- //verificar tipo de grafico, usar tag especifico no find
- if (NewData[0] == "bars") {
- $clonedDiv.find('h3').replaceWith('<h3 class="panel-title">'+ NewData[5] +'</h3>');
- $clonedDiv.find('p').replaceWith(bar);
- $clonedDiv.find("nvd3-multi-bar-chart[data='#6']").attr("data", NewData[6]);
- $clonedDiv.find("nvd3-multi-bar-chart[id='#7']").attr("id", NewData[7]);
- }
- else if (NewData[0] == "line") {
- $clonedDiv.find('h3').replaceWith('<h3 class="panel-title">' + NewData[5] + '</h3>');
- $clonedDiv.find('p').replaceWith(line);
- $clonedDiv.find("nvd3-line-with-focus-chart[data='#6']").attr("data", NewData[6]);
- $clonedDiv.find("nvd3-line-with-focus-chart[id='#7']").attr("id", NewData[7]);
- }
- else if (NewData[0] == "pie") {
- $clonedDiv.find('h3').replaceWith('<h3 class="panel-title">' + NewData[5] + '</h3>');
- $clonedDiv.find('p').replaceWith(pie);
- $clonedDiv.find("nvd3-pie-chart[data='#6']").attr("data", NewData[6]);
- $clonedDiv.find("nvd3-pie-chart[id='#7']").attr("id", NewData[7]);
- }
- /*else{ //table
-
- }*/
- return $clonedDiv.html();
when i see the result it presents me the CSS that is associated to each panel but the javascript function (Sortable, Hide, Accordion and the charts) won't work.
Can anyone give some help to fix this?
Thk