Tip: Use divs to organize your gadget elements

Tuesday, September 04, 2007 at 1:33 PM

Recently, while working on a gadget, I had a number of elements that needed to disappear as the mouse moved away from the gadget. Originally I was using code like this: label1.visible = false; label2.visible = false;.... But then I remembered the div element. I encapsulated all my labels in one div and wrote labelDiv.visible = false. Teo's knowledge base article describes other situations where the div element is useful.

Have a tip you'd like to share? Send it to gd-developer AT google DOT com.


james said...

i'd like to stress this is essential when managing complex UI. it also helps for positioning a group of related elements.

Teo said...

That's correct, this can save you a lot of stress. A good way to look at this is: whenever you add a UI element which can visually be grouped with others, stop and make a div on the way. You won't regret it in the future :)