table | NN 6 IE 4 DOM 1 | |||||||||||||||||||||||
The table object reflects the table element. Other objects related to the table object are: caption, col, colgroup, tbody, td, tfoot, thead, and tr. |
||||||||||||||||||||||||
HTML Equivalent | ||||||||||||||||||||||||
<table> |
||||||||||||||||||||||||
Object Model Reference | ||||||||||||||||||||||||
[window.]document.getElementById("elementID")
|
||||||||||||||||||||||||
Object-Specific Properties | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
Object-Specific Methods | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
Object-Specific Event Handler Properties | ||||||||||||||||||||||||
None. |
align | NN 6 IE 4 DOM 1 |
Read/Write | |
Defines the horizontal alignment of the element within its surrounding container. |
|
Example | |
document.getElementById("myTable").align = "center"; |
|
Value | |
Any of the three horizontal alignment constants: center | left | right. |
|
Default | |
left |
background | NN n/a IE 4 DOM n/a |
Read/Write | |
Provides the URL of the background image for the table. If you set a backgroundColor to the element as well, the color appears if the image fails to load; otherwise, the image overlays the color. |
|
Example | |
document.getElementById("myTable").background = "images/watermark.jpg"; |
|
Value | |
Complete or relative URL to the background image file. |
|
Default | |
None. |
bgColor | NN 6 IE 4 DOM 1 |
Read/Write | |
Specifies the background color of the element. This color setting is not reflected in the style sheet backgroundColor property. Even if the bgcolor attribute or bgColor property is set with a plain-language color name, the returned value is always a hexadecimal triplet. |
|
Example | |
document.getElementById("myTable").bgColor = "yellow"; |
|
Value | |
A hexadecimal triplet or plain-language color name. See Appendix A for acceptable plain-language color names. |
|
Default | |
Varies with browser and operating system. |
blur( ) | NN 2 IE 3 DOM 1 |
Removes focus from the current object, at which time the object's onblur event fires. Note that the range of elements capable of focus and blur (both the event and method) is limited in all browsers except for more recent versions of IE (see the shared tabindex attribute in Chapter 8). Most reliably for backward compatibility, apply the blur( ) method to blatantly focusable elements, such as text input and textarea elements. Assigning the attribute onfocus="this.blur( );" to a text input element, for instance, is a crude but effective backward-compatible way to largely disable a field for browsers that do not provide genuine element disabling. |
|
Use blur( ) and focus( ) methods in moderation on the same page. You can inadvertently trigger endless loops of blurring and focusing if alert dialog boxes are involved along the way. Moreover, be aware that when you invoke the blur( ) method on one object, some other object (perhaps the window object) receives an onfocus event. |
|
Parameters | |
None. |
|
Returned Value | |
None. |
border | NN 6 IE 4 DOM 1 |
Read/Write | |
Specifies the thickness of the border around the table (in pixels). This is the default 3-D-look border and should not be confused with borders created with style sheets. |
|
Example | |
document.getElementById("myTable").border = 4; |
|
Value | |
An integer value. A setting of zero removes the border entirely. |
|
Default | |
0 |
borderColor | NN n/a IE 4 DOM n/a |
Read/Write | |
Specifies the color of the table's border. Internet Explorer applies the color to all four lines that make up the interior border of a cell. Therefore, colors of adjacent cells do not collide. |
|
Example | |
document.getElementById("myTable").borderColor = "salmon"; |
|
Value | |
A hexadecimal triplet or plain-language color name. A setting of empty is interpreted as "#000000" (black). See Appendix A for acceptable plain-language color names. |
|
Default | |
Varies with operating system. |
borderColorDark, borderColorLight | NN n/a IE 4 DOM n/a |
Read/Write | |
The 3-D effect of table borders in Internet Explorer is created by careful positioning of light and dark lines around the page's background or default color. You can independently control the colors used for the dark and light lines by assigning values to the borderColorDark (left and top edges of the cell) and borderColorLight (right and bottom edges) properties. |
|
Typically, you should assign complementary colors to the pair of properties. There is also no rule that says you must assign a dark color to borderColorDark. The attributes merely control a well-defined set of lines so you can predict which lines of the border change with each attribute. |
|
Example | |
document.getElementById("myTable").borderColorDark = "blue"; document.getElementById("myTable").borderColorLight = "cornflowerblue"; |
|
Value | |
A hexadecimal triplet or plain-language color name. A setting of empty is interpreted as "#000000" (black). See Appendix A for acceptable plain-language color names. |
|
Default | |
Varies with operating system. |
caption | NN 6 IE 4(Win)/5(Mac) DOM 1 |
Read-only | |
Returns a reference to a caption element nested inside the table. From this reference you can access properties and methods of the caption object. In Netscape 6, you can create a new caption element, and assign that new element's reference to the caption property of a table, making the property read/write in that browser (although you really should be using the createCaption( ) method). For all browsers, however, you can modify properties of the caption object returned by the caption property. |
|
Example | |
var capText = document.getElementById("myTable").caption.innerHTML; |
|
Value | |
Object reference. |
|
Default | |
None. |
cellPadding | NN 6 IE 4 DOM 1 |
Read/Write | |
Specifies the amount of empty space between the (visible or invisible) border of a table cell and the content of the cell. Note that this property applies to space inside a cell. Minor adjustments to this property are not as noticeable when the table does not also display borders (in which case the cellSpacing property can assist in adjusting the space between cells). |
|
Example | |
document.getElementById("myTable").cellPadding = "15"; |
|
Value | |
A string value for a length in pixels or percentage. |
|
Default | |
0 |
cells | NN n/a IE 5(Win) DOM n/a |
Read-only | |
Returns a collection of all td elements inside the table. Entries in the array are in source code order of td elements. This property is more widely available for a tr element (one row at a time). |
|
Example | |
var totCells = document.getElementById("myTable").cells.length; |
|
Value | |
Reference to a cells collection object. |
|
Default | |
Array of zero length. |
cellSpacing | NN 6 IE 4 DOM 1 |
Read/Write | |
Specifies the amount of empty space between the outer edges of each table cell. If the table has a border, the effect of setting cellSpacing is to define the thickness of borders rendered between cells. Even without a visible border, the readability of a table often benefits from cell spacing, or a combination of cell spacing and cell padding. |
|
Example | |
document.getElementById("myTable").cellSpacing = "5"; |
|
Value | |
A string value for a length in pixels or percentage. |
|
Default | |
0 (with no table border); 2 (with table border). |
clientHeight, clientWidth | NN 7 IE 4 DOM n/a |
Read-only | |
Broadly speaking, these provide the height and width of the element's content, but with minor variations with respect to element padding among various operating system versions of IE and compatibility modes controlled by the DOCTYPE declaration. Not available for all element types in IE for Macintosh. For Netscape 7, values are zero except when an element's content overflows the viewable area, in which case the values reveal the dimensions of the viewable area (e.g., the browser window's content region for the document.body element). See the Section 9.2 at the beginning of this chapter for details. |
|
Example | |
var midHeight = document.body.clientHeight/2; |
|
Value | |
Integer pixel value. |
|
Default | |
0 |
cols | NN n/a IE 4 DOM 1 |
Read/Write | |
Specifies the number of columns of the table. The corresponding IE-specific cols attribute assists the browser in preparation for rendering the table. Without this attribute, the browser relies on its interpretation of all downloaded tr and td elements to determine how the table is to be divided. You cannot change the column makeup of a table from this property, despite its read/write status. See also the col object earlier in this chapter |
|
Example | |
document.getElementById("myTable").cols = 5; |
|
Value | |
Integer. |
|
Default | |
None. |
dataPageSize | NN n/a IE 4 DOM n/a |
Read/Write | |
Used with IE data binding, this property advises the browser how many instances of a table row must be rendered to accommodate the number of data source records set by this attribute. See lastPage( ), nextPage( ), and previousPage( ) methods for navigating through groups of records. |
|
Example | |
document.getElementById("inventoryTable").dataPageSize = 10; |
|
Value | |
Integer. |
|
Default | |
None. |
focus( ) | NN 2 IE 3 DOM 1 |
Gives focus from the current object, at which time the object's onfocus event fires. Note that the range of elements capable of focus and blur (both the event and method) is limited in all browsers except for more recent versions of IE (see the shared tabindex attribute in Chapter 8). Most reliably for backward compatibility, apply the focus( ) method to blatantly focusable elements, such as text input and textarea elements. |
|
To give a text box focus and pre-select all the text in the box, use the sequence of focus( ) and select( ) methods on the element. If this sequence is to occur after windows change (such as after an alert dialog box closes), place the methods in a separate function, and invoke this function through the setTimeout( ) method following the alert( ) method for the dialog. This allows IE/Windows to sequence statement execution correctly. |
|
Parameters | |
None. |
|
Returned Value | |
None. |
frame | NN 6 IE 4 DOM 1 |
Read/Write | |
Indicates which (if any) sides of a table's outer border (set with the border attribute or border property) are rendered. This property does not affect the interior borders between cells. |
|
Example | |
document.getElementById("orderForm").frame = "hsides"; |
|
Value | |
Any one case-insensitive frame constant (as a string):
|
|
Default | |
void (when border=0); border (when border is any other value) |
height, width | NN 6 (width only) IE 4 DOM 1 (width only) |
Read/Write | |
Specify the height and width in pixels of the element. Changes to these values are immediately reflected in reflowed content on the page. Only the width property is available in Netscape 6 (and the W3C DOM), as the table's height is considered to be the sum of the highest cell in each row. |
|
Example | |
document.getElementById("myTable").height = 250; |
|
Value | |
Integer. |
|
Default | |
None. |
recordNumber | NN n/a IE 4 DOM n/a |
Read-only | |
Used with IE data binding, returns an integer representing the record within the data set that generated the element (i.e., an element whose content is filled via data binding). Values of this property can be used to extract a specific record from an Active Data Objects (ADO) record set (see recordset property). Although this property is defined for all IE element objects, the other properties related to data binding belong to a subset of elements. |
|
Example | |
<script for="tableTemplate" event="onclick"> myDataCollection.recordset.absoluteposition = this.recordNumber; ... </script> |
|
Value | |
Integer. |
|
Default | |
null |
rows | NN 6 IE 4 DOM 1 |
Read-only | |
Returns a collection of tr elements inside the entire table. You can also get a group of rows for each table section (tbody, tfoot, and thead element objects). |
|
Example | |
var allTableRows = document.getElementById("myTable").rows; |
|
Value | |
Reference to a rows collection object. |
|
Default | |
Array of zero length. |
rules | NN 6 IE 4 DOM 1 |
Read/Write | |
Indicates where (if at all) interior borders between cells are rendered by the browser. In addition to setting the table to draw borders to turn the cells into a matrix, you can set borders to be drawn only to separate borders, columns, or any sanctioned cell grouping (thead, tbody, tfoot, colgroup, or col). The border attribute must be presenteither as a Boolean or set to a specific border sizefor any cell borders to be drawn. Do not confuse this property with the rules[ ] collection of styleSheet objects. Scripted changes to this property do not always yield the desired results, especially in early versions of Netscape 6. |
|
Example | |
document.getElementById("myTable").rules = "groups"; |
|
Value | |
Any one case-insensitive rules constant (as a string):
|
|
Default | |
none (when border=0); all (when border is any other value). |
scrollHeight, scrollWidth | NN 7 IE 4 DOM n/a |
Read-only | |
Originally implemented in IE 4 for elements that either scrolled or influenced an element's scroll (body, button, caption, div, fieldset, legend, marquee, and textarea), these properties return the pixel dimensions of an element, including elements that are larger than the viewable area in the browser window. This is in contrast to the clientHeight and clientWidth properties for scrollable elements, which return dimensions of only visible portions of the element. IE for the Macintosh, however, interprets the intent of the scroll- properties differently, returning the dimensions of the visible portion. |
|
Starting in IE 5 for Windows, all HTML elements have these properties, and the values for nonscrolling elements are the same as the offsetHeight and offsetWidth properties. Netscape 7 implements these properties for all elements, returning the height and width of the element, whether or not it's in view. The important point is that for key elements, such as the body, the properties mean different things and can disrupt cross-platform operation. |
|
Example | |
var midPoint = document.body.scrollHeight/2; |
|
Value | |
Positive integer or zero. |
|
Default | |
None. |
scrollLeft, scrollTop | NN 7 IE 4 DOM n/a |
Read/Write | |
Provide the distance in pixels between the actual left or top edge of the element's physical content and the left or top edge of the visible portion of the content. Setting these properties allows you to use a script to adjust the scrolling of content within a scrollable container, such as text in a textarea element or an entire document in the browser window or frame. When the content is not scrolled, both values are zero. Setting the scrollTop property to 15 scrolls the document upward by 15 pixels in the window; the scrollLeft property is unaffected unless explicitly changed. The property values change as the user adjusts the scrollbars. This is important for some event-driven positioning tasks in IE for Windows because the coordinate system for event offset measurements are with respect to the visible area of a page in the browser window. You must add document.body scrolling factors to align event coordinates with body content positions (see the element dragging example in Chapter 6). Starting with IE 5 for Windows, the scrollLeft and scrollTop properties are available for all HTML element objects, but values for unscrollable elements are zero. |
|
Example | |
document.body.scrollTop = 40; |
|
Value | |
Positive integer or zero. |
|
Default | |
0 |
summary | NN 6 IE 6 DOM 1 |
Read-only | |
Reflects the HTML 4 summary attribute, which provides no particular functionality in mainstream browsers. But you can assign a value to it in the source code to convey data to a script that reads the property. |
|
Example | |
var data = document.getElementById("myTable").summary; |
|
Value | |
String. |
|
Default | |
Empty string. |
tabIndex | NN 6 IE 4 DOM 1 |
Read/Write | |
This is a number that indicates the sequence of this element within the tabbing order of all focusable elements in the document. Tabbing order follows a strict set of rules. Elements that have values other than zero assigned to their tabIndex properties are first in line when a user starts tabbing in a page. Focus starts with the element with the lowest tabIndex value and proceeds in order to the highest value, regardless of physical location on the page or in the document. If two elements have the same tabIndex values, the element that comes earlier in the document receives focus first. Next come all elements that either don't support the tabIndex property or have the value set to zero. These elements receive focus in the order in which they appear in the document. |
|
The W3C DOM and Netscape 6 limit the tabIndex property to the following element objects: a, area, button, input, object, select, textarea. To this list, IE 4 adds applet, body, div, embed, isindex, marquee, span, table, and td. IE 5 adds every other renderable element. A negative value in IE (only) removes an element from tabbing order entirely. |
|
Links and anchors cannot be tabbed to with the Mac version of IE 4, so the tabIndex property for a element objects is ignored in that version. |
|
Example | |
document.getElementById("link3").tabIndex = 6; |
|
Value | |
Integer. |
|
Default | |
0 |
tBodies[ ] | NN 6 IE 4(Win)/5(Mac) DOM 1 |
Read-only | |
Returns a collection of tBody objects in the current table. Every table element has at least one (explicit or implied) tBody object nested inside. |
|
Example | |
var bodSections = document.getElementById("myTable").tBodies; |
|
Value | |
Reference to a collection of tBody objects. |
|
Default | |
Array of length one. |
tFoot | NN 6 IE 4(Win)/5(Mac) DOM 1 |
Read-only | |
Returns a reference to the tfoot element object if one has been defined for the table. If no tfoot element exists, the value is null. You can access tfoot element object properties and methods through this reference if you like. This property is available only on the Win32 version of Internet Explorer 4. |
|
Example | |
var tableFootTxt = document.getElementById("myTable").tFoot.firstChild.nodeValue; |
|
Value | |
tfoot element object reference. |
|
Default | |
null |
tHead | NN 6 IE 4(Win)/5(Mac) DOM 1 |
Read-only | |
Returns a reference to the thead element object if one has been defined for the table. If no thead element exists, the value is null. You can access thead element object properties and methods through this reference if you like. This property is available only on the Win32 version of Internet Explorer 4. |
|
Example | |
var tableHeadTxt = document.getElementById("myTable").tHead.firstChild.nodevalue; |
|
Value | |
thead element object reference. |
|
Default | |
null |
width | |
See height. |
createCaption( ), deleteCaption( ) | NN 6 IE 4 DOM 1 |
Add or remove a caption element nested within the current table element. If no caption exists, the creation method produces an empty element, which your scripts must then populate with caption text (through common element content modification techniques). If a caption exists, the method is essentially ignored, and returns a reference to the existing caption element. |
|
Parameters | |
None. |
|
Returned Value | |
Reference to new caption element (for createCaption( )); nothing for deleteCaption( ). |
createTFoot( ), createTHead( ), deleteTFoot( ), deleteTHead( ) | NN 6 IE 4 DOM 1 |
Add or remove a thead or tfoot element nested within the current table element. If no head or foot table section exists, the creation method produces an empty element, which your scripts must then populate with rows (through thead.insertRow( ) and tfoot.insertRow( ) methods). If the desired table section exists, the method is essentially ignored, and returns a reference to the existing thead or tfoot element. |
|
Parameters | |
None. |
|
Returned Value | |
Reference to newly created element (for createTFoot( ) and createTHead( )); Nothing for deleteTHead( ) and deleteTFoot( ). |
deleteRow( ) | NN 6 IE 4 DOM 1 |
deleteRow(index) | |
Removes a tr element nested within the current table element. The integer parameter points to the zero-based item in the rows collection. To repopulate a table with new or sorted content, empty the table (or just a table section) with iterative calls to the deleteRow( ) method: while (tableReference.rows.length> 0) { tableReference.deleteRow(0); } |
|
Parameters | |
|
|
Returned Value | |
None. |
insertRow( ) | NN 6 IE 4(Win) DOM 1 |
insertRow(index) | |
Inserts a tr element nested within the current table element. The integer parameter points to the zero-based index in the rows collection where the new row should go, but in IE you can also use the shortcut value of -1 to append the row to the end of the collection. Adding the row inserts an empty element, to which you add cells via the insertCell( ) method. Unfortunately, scripting the addition of table rows and cells in IE for the Macintosh (including Version 5.1) is very broken, yielding elephantine row and cell dimensions. For nonnested tables, you might be able to get away with regular document tree node creation and insertion instead of the table (and related) object convenience methods. |
|
Parameters | |
|
|
Returned Value | |
Reference to the newly inserted row. |
lastPage( ), nextPage( ), previousPage( ) | NN n/a IE 4/5 DOM n/a |
Advises the data binding facilities to load the last, next, or previous group of records from the data source to fill the number of records established with the dataPageSize property. The lastPage( ) method is available in IE 5 or later. |
|
Parameters | |
None. |
|
Returned Value | |
None. |
moveRow( ) | NN n/a IE 5(Win) DOM n/a |
moveRow(indexToMove, destinationIndex) | |
Moves a row in the table from its original location to a different row position. The first parameter is a zero-based index of the row (within the rows collection) you wish to move. The second parameter is the index of the row before which you want to move the row. As a method of the table object, moveRow( )'s index parameters include the first row, which may contain th elements you don't want to move. Invoke the method on the tbody object if you want counting to be just within a table section. |
|
Parameters | |
|
|
Returned Value | |
Reference to the moved row. |
refresh( ) | NN n/a IE 4 DOM n/a |
Advises the data binding facilities to reload the current page of data from the data source. If your table is retrieving frequently-changing data from a database, you can create a setTimeout( ) loop to invoke document.getElementById("myTable").refresh( ) as often as users would want updated information from the database. |
|
Parameters | |
None. |
|
Returned Value | |
None. |