Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply a function to two elements?

I have two elements #DateTimeStart, #DateTimeEnd, I would like apply my datetimepicker to both.

With this code I cannot have 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 like but with less code

// This code works
$(document).ready(function () {
    $('#DateTimeStart').datetimepicker({
        addSliderAccess: true,
        sliderAccessArgs: { touchonly: false }
    });  
    $('#DateTimeEnd').datetimepicker({
        addSliderAccess: true,
        sliderAccessArgs: { touchonly: false }
    });
});
like image 426
GibboK Avatar asked Dec 06 '25 17:12

GibboK


1 Answers

Just separate selector with comma:

$("#DateTimeStart, #DateTimeEnd").datetimepicker({
    addSliderAccess: true,
    sliderAccessArgs: { touchonly: false }
});

In jQuery documentation it is called as Multiple Selector.

like image 70
VisioN Avatar answered Dec 08 '25 06:12

VisioN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!