ani_css ani_css - 6 months ago 60
Javascript Question

Class instead of getElementById

I want to use the Pikaday script and it gives me JavaScript code to add to my project. Something like:

var picker = new Pikaday({ field: document.getElementById('datepicker') });

Is there any way to use a class instead of
? For example:

var picker = new Pikaday({ field: $('.datepicker') });


if you are only using newer browsers you can use


This will give you the first element that matches the class. Here is the Caniuse link

For older browsers you can use