inadcod inadcod - 7 months ago 28
jQuery Question

highcharts change rendered image source on click

I have created a chart based on Highcharts plugin, in which I have rendered an image (a button: "zoom.png").

This image has an

event which resets my

I need to change the source of this image when the button is clicked; then change it back after the second click.

I managed to change the source of the image for the first click (it changes to "zoom1.png"); but when I click the button again it doesn't revert to the original source ("zoom.png")

Here is an example: JsFiddle.

[Edit]: Updated JSFiddle With Cool URIs for the Images

Answer Source

The condition you are checking for

if ($('image').attr('href', '')) {

is invalid, as it is preceeded by

chart = new Highcharts.Chart(options); 

This creates the image again (in the newly created chart's load handler) with the original zoom.png hence the condition is always true, except the very 1st time, when there is no image.

You need to have a different check like a boolean variable out side to this chart which you will check and then flip every time it is clicked