Here I have to create highchart dynamically based on dynamic id which generates from index++. when I click submit1 button chart will create dynamically.Again when I click download button an array will be showing in console based on created id.When I console it its showing as the array like [$('#chart-0'),$('#chart-1')] which I created dynamically,same time when I hardcode the samearray and console it its showing as created chart [r.fn.init(1), r.fn.init(1)],here what I need is when I console ('console.log(strreplace)') the created array also should display as chart same as like harcoded (console.log(elements)) value.Here is code below
html
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<input type="button" id="download" value="download" /> click to console
<div><button id="button1" class="button1">submit1</button></div>
script
$(document).ready(function() {
var index = 0;
var id = [];
$('#button1').on('click', function() {
$('body').append($("<div id='chart-" + index + "'></div>"));
Highcharts.chart('chart-' + index, {
series: [{
data: [1, 2, 3]
}]
});
var temp="$('#chart-"+index+"')";
id.push(temp);
console.log('chart' + index);
index++;
});
$('#download').on('click', function() {
var string = JSON.stringify(id);
var strreplace = string.replace (/"/g,'');
console.log(strreplace);
var elements = [$('#chart-0'),$('#chart-1')];
console.log(elements);
});
});