Context Menu for programaticallly created elements

Is it possible to create context menu for programmatically created HTML Elements using javascript:

var divElem = document.createElement(“div”);
var ul = document.createElement(“ul”)
var li1 = document.createElement(“li”)
li1.innerHTML =“List1”
li2 = document.createElement(“li2”)
li2.innerHTML =“List1”

If so then how to css for this?

Once you add the element to the body, any CSS that applies would take effect, both for “ul” and “li” elements as well as for any classes that you declare for the elements that you create.

This is easier to do in version 1.7, where we have added support for the HTMLInfo class. Please see GoJS - Build Interactive Diagrams for the Web.

Actually I need to create different context menu for different Nodes. It may be 10 or 20 menus. Is that possible?

Sure, it’s just HTML. In case you haven’t found it yet in 1.7:

We think this is simpler than what you had to do in earlier versions to get the same effect.

And one more thing I have maintain two context menu for each node’s. One By Double clicking and other by right clicking context menu.

Well, unless one context menu is similar to the other one, so that you can make elements of it visible or not depending on how it got invoked, you won’t be able to use the GraphObject.contextMenu property for both menus.

Instead you’ll need to implement both GraphObject.doubleClick and GraphObject.contextClick** event handlers, doing similar things but with different HTML context menus. I’m sorry I don’t have an example for you at this time, although you should be able to figure it out – it’s almost all independent of GoJS.