How do I apply a function to two elements?
I have two elements #DateTimeStart
, #DateTimeEnd
I would like to apply my datetimepicker
to both.
With this code I cant get the result .. any idea what I am doing wrong here?
$(document).ready(function () {
// This does not work
$('#DateTimeStart', '#DateTimeEnd').datetimepicker({
addSliderAccess: true,
sliderAccessArgs: { touchonly: false }
});
});
What I am trying to achieve is similar but with less code
// This code works
$(document).ready(function () {
$('#DateTimeStart').datetimepicker({
addSliderAccess: true,
sliderAccessArgs: { touchonly: false }
});
$('#DateTimeEnd').datetimepicker({
addSliderAccess: true,
sliderAccessArgs: { touchonly: false }
});
});
Just a separate semicolon selector:
$("#DateTimeStart, #DateTimeEnd").datetimepicker({
addSliderAccess: true,
sliderAccessArgs: { touchonly: false }
});
It's called Multiple Selector in the jQuery documentation .
Assign both elements to the class: "datepickerclass" and then use the code below
$('.datepickerclass').datetimepicker({
addSliderAccess: true,
sliderAccessArgs: { touchonly: false }
});
This way you can have any number of elements with a dumper attached