Login Register

Button behaviour

Hello,

Given this button:

<button id="d_back" dojoType="dijit.form.Button">Back</button>

If I try to add an event:

var el= document.getElementById('d_back');
  el.onclick= _back;

It seems to be removed by dijit. However this functions correctly:

<button id="d_back" onclick="d_back" dojoType="dijit.form.Button">Back</button>

It would be good if any existing event should not be cleared as currently seems to be the behaviour.

Also, slightly off topic perhaps, I think dijit.byId('X') should return document.getElementById('X') if the original code (that I've not looked at) returns null. I assume:

dojo.require("dojo.parser");

does not register events to after the page has loaded, so any JS running when the page loads must use document.getElementById.

John

If you use the dojo parser

If you use the dojo parser to create a widget (via dojoType, like you are), the original node is removed - so dojo.byId("d_back") will not be found.

Use dijit.byId("d_back") to get the widget itself.

Use dijit.byId("d_back").srcNodeRef to get a reference to the *original* DOM node (the one that got removed).

Use dijit.byId("d_back").domNode to get a reference to the *current* top-level DOM node for the widget.

Remember depending on when the parser runs, your options may or may not have effect. The best thing to do, if you want total control is to set parseOnLoad to false, and in your dojo.addOnLoad function, call dojo.parser.parse() when you want it to run.

Dijit makes a best-effort to

Dijit makes a best-effort to preserve some of the semantics for standard html buttons, including turning any onclick attribute into the handler for its onClick method. But you need to understand that the button element != the widget that comes out after the parser has run. In most cases the original element is treated as configuration and placement data for the widget that gets created, no more. If the need to assign _back to the onclick is come about through some timing issue with when the parser runs vs. other scripts on the page, then do as toonetown suggests and turn parseOnLoad off, and call dojo.parser.parse() at the best time for you.