How to Cache DOM Variable in jQuery
Demo
Using jquery and highchart.js (+ exporting.js module) I am trying to export the chart by a custom button like below
- <button type="button" id="chartpdf" data-chart="chart1" class="pdf-download">PDF</button>
While the code is exporting the chart in hard-coded format like this
- chart1.exportChart({type: "application/pdf"});
it is not working when trying to dynamically get the
chart1 from the element data
attribute data-chart="chart1"
-
- $(document).on("click", ".pdf-download", function(){
- $(this).data('chart').exportChart({type: "application/pdf"});
- });
can you please let me know how to fix this?
Thanks