Plotly javascript. 'plotly_click' gets on is not a function
<p>I am attempting to create an onclick event on my plotly chart. Following the documentation i have created the following chart:</p>

<pre><code>var graphDiv = document.getElementById('uniqueId');
Plotly.newPlot('uniqueId', charData, layout);
graphDiv.on('plotly_click', function (data) {
    var i = 0;
})
</code></pre>

<p>However when i run this i get the following error:</p>

<pre><code>graphDiv.on is not a function
</code></pre>

<p>So can anyone tell me what im doing wrong?</p>

<p>Note i have also attempted with jquery:</p>

<pre><code>$('#uniqueId').on('plotly_click', function(){})
</code></pre>

<p>This didnt throw an error but the function was not called when clicking the chart.</p>

<p>fiddle:</p>

<p><a href="https://jsfiddle.net/c1kt3r82/127/" rel="nofollow noreferrer">https://jsfiddle.net/c1kt3r82/127/</a></p>