To accomplish this, in the Url parameter of the Add method, we write something like:
"javascript:
myFunction();void(0);"
Make sure you leave UrlTarget parameter null or not specified at all.
Example:
tm1.Add("parentId", "itemId", "item text",
"javascript:alert('you clicked me');void(0);", null);
When user will click on the item, an alert box will pop up.
To try it, click on IBM item in the following menu: