caption()
Get / set the table's caption.
Description
HTML tables have an optional element called caption
which can be used to show the title of a table to the end user. This can greatly enhance accessibility since it can give a summary of the contents of the table without the end user needing to read the surrounding text.
This method is provides to control the contents of a DataTables' caption
element.
Types
function caption()
- Description:
Get the contents of the
caption
element for the table.Note that if the API instance references multiple tables, only the first table in the collection will be considered for the getter.
- Returns:
Contents of the caption element. Will be
null
if there is no caption.
function caption( set [, side ] )
- Description:
Set the contents of the
caption
element. If the table doesn't have acaption
element, one will be created automatically.Note that is the API instance references multiples tables, the caption will be set for all tables referenced.
- Parameters:
Name Type Optional 1 set
No The value to show in the table's
caption
.2 side
Yes Typically the position of the
caption
element will be defined by thecaption-side
CSS property for the table, but this option provides the ability to set that option directly.It can be given
top
orbottom
. If not given at all, the position of the caption relative to the table will be defined by the page's CSS. By default in browsers this is above the table.- Returns:
DataTables API instance for chaining.
Examples
Set the table's caption:
var table = new DataTable('#myTable');
table.caption('Table 1: Class averages');
Set the table's caption and display at the bottom of the table:
var table = new DataTable('#myTable');
table.caption('Table 2: Year averages', 'bottom');
Related
The following options are directly related and may also be useful in your application development.