View Full Version : How to "getIconClass" to set icon of another item the same?

27 Sep 2009, 8:45 AM
How can I determine the icon class of an item and use it as the icon class of another item?

I have a TreePanel with some nodes that have iconCls set. On clicking a node, a tab is dynamically created and added to a TabPanel container. I'd like to be able to set the icon class of the dynamically created tab to that of the clicked node.

I see there is a setIconClass method (great) but no "getIconClass" or equivalent.

Thanks for any tips.


27 Sep 2009, 9:11 AM
If you are setting the icon through iconCls of the tree node, then you can get the cls by calling treenode.initialConfig.iconCls.

Otherwise you have to traverse to the iconEl like this and then get all the classNames:

var imgEl = treenode.getUI().getIconEl()

this will give you the img element for the icon, you can get all the classes by calling:


from this you have to look for anything other than "x-tree-node-icon", which should be the iconClass you want.