Variable reference to object

0

In the function for the creation of a google chart in javascript I have the variable of a div on which I draw the graphic.

The variable in question is containerDiv, which is a string with the id of the div.

I would need, instead of drawing the graph itself, to draw a jpg of it.

google.visualization.events.addListener(drawChart, "ready", function () {
                containerDiv.innerHTML = \'<img src="\' + chart.getImageURI() + \'">\';
            });

This code I found on the web, but I'm not sure that it's being used properly.

How do I make containerDiv.innerHTML reference the object contained within the containerDiv string?

    
asked by Sebastián Labonia 22.06.2016 в 16:09
source

1 answer

2

To refer to the containerDiv you should look for it in your document, for this you must do the following:

Native JS Version

var containerDiv = document.getElementById("containerDiv")

Jquery Version

var containerDiv = $("#containerDiv")

Clearly assuming that your div in question has the id="containerDiv" , that is, something like the following:

<div id="containerDiv"></div>
    
answered by 22.06.2016 / 16:16
source