How to get the Diagram

I am a newbie starting to use GoJS and have a basic question

I have created a new Diagram and want to later get access to it in another function which gets called upon click of a button, how do I get access to the diagram object again? I did set the div for the diagram and have access to the div ID

Thanks,
Vineesh

Are you talking about the click of a “Button” in GoJS, or a click of an HTML Button?

In the former case, there will be two arguments to the click function, as described at GraphObject | GoJS API. The first argument is an InputEvent, and InputEvent.diagram will return a reference to the Diagram in which the event happened. The second argument is a GraphObject, which in your case will be the “Button” itself; in this case GraphObject.diagram will return a reference to the Diagram that the object is in.

In the latter case (an HTML Button), there’s no relationship with any Diagram, of course. But since you have the DIV id, you could call the static function Diagram.fromDiv.

Thanks a lot for quick response. That worked.