val()
Get / set the value of the DateTime instance.
Please note - this property requires the DateTime extension for DataTables.
Description
Get or set the value for the DateTime instance. If the set parameter is provided then a DateTime instance is provided for chaining. If not then the value stored within DateTime is returned as a Date.
Types
val()
Get the value of the DateTime instance.
Returns:
Date
Date instance representing the current date selected within the DateTime instance.
val(set)
Set the value of the DateTime instance.
Parameters:
Name | Type | Optional | |
---|---|---|---|
1 | set | No | |
The value to be set. |
Returns:
DateTime
Self for chaining.
Examples
Get a value from the input:
let el = document.getElementById('example');
let dt = new DateTime(el);
el.addEventListener('change', function () {
console.log('Selected value is: ', dt.val());
});
Set a value into the input:
let dt = new DateTime(document.getElementById('example'));
dt.val('2021-12-31');