I'm not entirely clear on what exactly you're trying to achieve. Could you provide some more background and details?
Are you trying to put the name of a widget in the class of the widget? Or the ID? If it's a Mendix Widget/UI element (I think this is what you mean), there will be a classname indicating what it is in the top HTML element, with a mx- prefix.
Example at https://ux.mendix.com/theme-creator.html:
<div class="mx-navigationtree mx-name-navigationTree2" id="mxui_widget_NavigationTree_1" widgetid="mxui_widget_NavigationTree_1">
mx-navigationtree indicates that it's a navigation tree, as will mx-datagrid be added as a class for a datagrid, etc. You can use these classnames, combined with IDs for automated testing.
Does this answer your question?
In Javascript you can get a list of all the widgets when you use:
dijit.registry._hash
This will actually contain all the names of the widgets as keys in this object