title: How to set target property when simulating mouseclick in javascript?
body: <p>I want to simulate a mouseclick in my javascript code which uses dojo. The action for a real mouseclick will be registered using dojo-stuff with "ondijitclick". </p>
  
  <p>I know which method/function gets called and I also have the dijit object to call this method. The method expects an function object as parameter, so I'm creating a new MouseEvent object. This all works fine, except that I need to set the target value of this event and I can't figure out how to do this. This is needed because later exception handling is accessing the target-property and I can't avoid this.</p>
  
  <p>So far the code I have:</p>
  
  <pre><code>    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
          });
          dijit.byId(node.id)._doEvent(event);
      });
  </code></pre>
  
  <p>If I add the following line</p>
  
  <pre><code>            'target' : target,
  </code></pre>
  
  <p>in the MouseEvent creation, the property will not be set (but all other properties will be) and the target-property will be null, but target itself is not null).</p>
  
  <p>Is it even possible to set the target property somehow? If it is possible I'm wondering what I am doing wrong?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I have found an very dirty solution, which includes a minimal but undesired change in the widget coming from the underlying framework.</p>
  
  <p>I could only achieve that the <code>relatedTarget</code> property is set while <code>target</code> still will be null. If checking the <code>target</code> property for null and if it is null taking the <code>relatedTarget</code> in the widgets method everything works as wished. The simulated click and the real click are both working properly.</p>
  
  <p>The only problem with this solution is that I hasve to modify the widget in the framework. This is something what we won't do in a release-build. This is a possible solution in general, but in reality this solution is not acceptable for us.</p>
  
  <p>So there is still the question how I can set the <code>target</code> property with the right value. As the solution shows in genereal it works all except setting the <code>target</code> property.</p>
  
  <p>I can't see that this is achieved in the solution presented by Ferry Kranenburg. If this solution does what I need it would be nice if someone could explain the trick to me.</p>