How to set target property when simulating mouseclick in javascript?

The target property of the event object can not be accessed when the event is initialized. It points to the first element that receives the event once it is triggered and is set internally by JavaScript to that element. So if you need a special element being the event target you have to dispatch the event to that element.

One way would be to overwrite the native target property with your own method, but this may affect the bubbling behavior of the event.

dojo.query(".mybutton").forEach(function (node) {
  var target = dojo.query(".myclass").parents("#" + node.id)[0];
  var event = new MouseEvent('click', {
    'view' : window,
    'bubbles': true,
    'cancelable': true
  });
  Object.defineProperty(event, 'target', {value: target, enumerable: true});
  dijit.byId(node.id)._doEvent(event);
});