Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dojo.byId() works but dijit.byId() doesn't

Tags:

dojo

I have a select field with id appointment_stylist_id. For some reason, the first one of these returns my element but the second one returns undefined:

  console.log(dojo.byId('appointment_stylist_id'));
  console.log(dijit.byId('appointment_stylist_id'));

Any idea why?

like image 982
Jason Swett Avatar asked Apr 20 '11 00:04

Jason Swett


1 Answers

This is because dojo.byId does what you want (find a DOM element with a particular ID), and dijit.byId doesn't do that.

dijit.byId is a function for looking up a specific widget by its assigned name (id). This function is similar to dojo.byId but whereas dojo.byId returns DOMNodes, dijit.byId returns a JavaScript object that is the instance of the widget.

...

dijit.byId and dojo.byId are often confused, particularly by first time users. This function should be used when you wish to obtain a direct handle the the JavaScript object instance of your widget and access functions of that widget.

http://dojotoolkit.org/reference-guide/dijit/byId.html

See also

What the difference between dojo.byId and dijit.byId?

like image 62
Matt Ball Avatar answered Oct 02 '22 01:10

Matt Ball