Example: Adding A Context Menu To A Table (YUI Library) [Examples Home]

When adding context menus to large data structures like a <table> or large list (<ol> or <ul>), it is recommended to bind a single YAHOO.widget.ContextMenu instance to the structure's root element, than to a set of its child nodes (<tr>s or <li>s). Doing so significantly improves the performance of a web page or application by reducing the number of "contextmenu" event handlers as well as the number of YAHOO.widget.ContextMenu instances in memory.

This example demonstrates this technique, as well as how to create a context-sensitive context menu; a context menu whose content changes based on the element that triggered its display.

Please Note: Opera users will need to do the following to use this example:

Row 0, Column 1Row 0, Column 2Row 0, Column 3Row 0, Column 4
Row 1, Column 1Row 1, Column 2Row 1, Column 3Row 1, Column 4
Row 2, Column 1Row 2, Column 2Row 2, Column 3Row 2, Column 4
Row 3, Column 1Row 3, Column 2Row 3, Column 3Row 3, Column 4
Row 4, Column 1Row 4, Column 2Row 4, Column 3Row 4, Column 4
Row 5, Column 1Row 5, Column 2Row 5, Column 3Row 5, Column 4
Row 6, Column 1Row 6, Column 2Row 6, Column 3Row 6, Column 4
Row 7, Column 1Row 7, Column 2Row 7, Column 3Row 7, Column 4
Row 8, Column 1Row 8, Column 2Row 8, Column 3Row 8, Column 4
Row 9, Column 1Row 9, Column 2Row 9, Column 3Row 9, Column 4
Row 10, Column 1Row 10, Column 2Row 10, Column 3Row 10, Column 4
Row 11, Column 1Row 11, Column 2Row 11, Column 3Row 11, Column 4
Row 12, Column 1Row 12, Column 2Row 12, Column 3Row 12, Column 4
Row 13, Column 1Row 13, Column 2Row 13, Column 3Row 13, Column 4
Row 14, Column 1Row 14, Column 2Row 14, Column 3Row 14, Column 4
Row 15, Column 1Row 15, Column 2Row 15, Column 3Row 15, Column 4
Row 16, Column 1Row 16, Column 2Row 16, Column 3Row 16, Column 4
Row 17, Column 1Row 17, Column 2Row 17, Column 3Row 17, Column 4
Row 18, Column 1Row 18, Column 2Row 18, Column 3Row 18, Column 4
Row 19, Column 1Row 19, Column 2Row 19, Column 3Row 19, Column 4
Row 20, Column 1Row 20, Column 2Row 20, Column 3Row 20, Column 4
Row 21, Column 1Row 21, Column 2Row 21, Column 3Row 21, Column 4
Row 22, Column 1Row 22, Column 2Row 22, Column 3Row 22, Column 4
Row 23, Column 1Row 23, Column 2Row 23, Column 3Row 23, Column 4
Row 24, Column 1Row 24, Column 2Row 24, Column 3Row 24, Column 4
Row 25, Column 1Row 25, Column 2Row 25, Column 3Row 25, Column 4
Row 26, Column 1Row 26, Column 2Row 26, Column 3Row 26, Column 4
Row 27, Column 1Row 27, Column 2Row 27, Column 3Row 27, Column 4
Row 28, Column 1Row 28, Column 2Row 28, Column 3Row 28, Column 4
Row 29, Column 1Row 29, Column 2Row 29, Column 3Row 29, Column 4
Row 30, Column 1Row 30, Column 2Row 30, Column 3Row 30, Column 4
Row 31, Column 1Row 31, Column 2Row 31, Column 3Row 31, Column 4
Row 32, Column 1Row 32, Column 2Row 32, Column 3Row 32, Column 4
Row 33, Column 1Row 33, Column 2Row 33, Column 3Row 33, Column 4
Row 34, Column 1Row 34, Column 2Row 34, Column 3Row 34, Column 4
Row 35, Column 1Row 35, Column 2Row 35, Column 3Row 35, Column 4
Row 36, Column 1Row 36, Column 2Row 36, Column 3Row 36, Column 4
Row 37, Column 1Row 37, Column 2Row 37, Column 3Row 37, Column 4
Row 38, Column 1Row 38, Column 2Row 38, Column 3Row 38, Column 4
Row 39, Column 1Row 39, Column 2Row 39, Column 3Row 39, Column 4
Row 40, Column 1Row 40, Column 2Row 40, Column 3Row 40, Column 4
Row 41, Column 1Row 41, Column 2Row 41, Column 3Row 41, Column 4
Row 42, Column 1Row 42, Column 2Row 42, Column 3Row 42, Column 4
Row 43, Column 1Row 43, Column 2Row 43, Column 3Row 43, Column 4
Row 44, Column 1Row 44, Column 2Row 44, Column 3Row 44, Column 4
Row 45, Column 1Row 45, Column 2Row 45, Column 3Row 45, Column 4
Row 46, Column 1Row 46, Column 2Row 46, Column 3Row 46, Column 4
Row 47, Column 1Row 47, Column 2Row 47, Column 3Row 47, Column 4
Row 48, Column 1Row 48, Column 2Row 48, Column 3Row 48, Column 4
Row 49, Column 1Row 49, Column 2Row 49, Column 3Row 49, Column 4
Row 50, Column 1Row 50, Column 2Row 50, Column 3Row 50, Column 4
Row 51, Column 1Row 51, Column 2Row 51, Column 3Row 51, Column 4
Row 52, Column 1Row 52, Column 2Row 52, Column 3Row 52, Column 4
Row 53, Column 1Row 53, Column 2Row 53, Column 3Row 53, Column 4
Row 54, Column 1Row 54, Column 2Row 54, Column 3Row 54, Column 4
Row 55, Column 1Row 55, Column 2Row 55, Column 3Row 55, Column 4
Row 56, Column 1Row 56, Column 2Row 56, Column 3Row 56, Column 4
Row 57, Column 1Row 57, Column 2Row 57, Column 3Row 57, Column 4
Row 58, Column 1Row 58, Column 2Row 58, Column 3Row 58, Column 4
Row 59, Column 1Row 59, Column 2Row 59, Column 3Row 59, Column 4
Row 60, Column 1Row 60, Column 2Row 60, Column 3Row 60, Column 4
Row 61, Column 1Row 61, Column 2Row 61, Column 3Row 61, Column 4
Row 62, Column 1Row 62, Column 2Row 62, Column 3Row 62, Column 4
Row 63, Column 1Row 63, Column 2Row 63, Column 3Row 63, Column 4
Row 64, Column 1Row 64, Column 2Row 64, Column 3Row 64, Column 4
Row 65, Column 1Row 65, Column 2Row 65, Column 3Row 65, Column 4
Row 66, Column 1Row 66, Column 2Row 66, Column 3Row 66, Column 4
Row 67, Column 1Row 67, Column 2Row 67, Column 3Row 67, Column 4
Row 68, Column 1Row 68, Column 2Row 68, Column 3Row 68, Column 4
Row 69, Column 1Row 69, Column 2Row 69, Column 3Row 69, Column 4
Row 70, Column 1Row 70, Column 2Row 70, Column 3Row 70, Column 4
Row 71, Column 1Row 71, Column 2Row 71, Column 3Row 71, Column 4
Row 72, Column 1Row 72, Column 2Row 72, Column 3Row 72, Column 4
Row 73, Column 1Row 73, Column 2Row 73, Column 3Row 73, Column 4
Row 74, Column 1Row 74, Column 2Row 74, Column 3Row 74, Column 4
Row 75, Column 1Row 75, Column 2Row 75, Column 3Row 75, Column 4
Row 76, Column 1Row 76, Column 2Row 76, Column 3Row 76, Column 4
Row 77, Column 1Row 77, Column 2Row 77, Column 3Row 77, Column 4
Row 78, Column 1Row 78, Column 2Row 78, Column 3Row 78, Column 4
Row 79, Column 1Row 79, Column 2Row 79, Column 3Row 79, Column 4
Row 80, Column 1Row 80, Column 2Row 80, Column 3Row 80, Column 4
Row 81, Column 1Row 81, Column 2Row 81, Column 3Row 81, Column 4
Row 82, Column 1Row 82, Column 2Row 82, Column 3Row 82, Column 4
Row 83, Column 1Row 83, Column 2Row 83, Column 3Row 83, Column 4
Row 84, Column 1Row 84, Column 2Row 84, Column 3Row 84, Column 4
Row 85, Column 1Row 85, Column 2Row 85, Column 3Row 85, Column 4
Row 86, Column 1Row 86, Column 2Row 86, Column 3Row 86, Column 4
Row 87, Column 1Row 87, Column 2Row 87, Column 3Row 87, Column 4
Row 88, Column 1Row 88, Column 2Row 88, Column 3Row 88, Column 4
Row 89, Column 1Row 89, Column 2Row 89, Column 3Row 89, Column 4
Row 90, Column 1Row 90, Column 2Row 90, Column 3Row 90, Column 4
Row 91, Column 1Row 91, Column 2Row 91, Column 3Row 91, Column 4
Row 92, Column 1Row 92, Column 2Row 92, Column 3Row 92, Column 4
Row 93, Column 1Row 93, Column 2Row 93, Column 3Row 93, Column 4
Row 94, Column 1Row 94, Column 2Row 94, Column 3Row 94, Column 4
Row 95, Column 1Row 95, Column 2Row 95, Column 3Row 95, Column 4
Row 96, Column 1Row 96, Column 2Row 96, Column 3Row 96, Column 4
Row 97, Column 1Row 97, Column 2Row 97, Column 3Row 97, Column 4
Row 98, Column 1Row 98, Column 2Row 98, Column 3Row 98, Column 4
Row 99, Column 1Row 99, Column 2Row 99, Column 3Row 99, Column 4