jQuery addClass example
Change class name on click in jQuery
by diogenesgg
HTML
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<p>Date: <input type="text" class="datepicker"></p>
JavaScript
$(document).on('focus', ".datepicker", function () {
if( $(this).hasClass('hasDatepicker') === false ) {
$(this).datepicker({
dateFormat : 'yy-mm-dd',
autoSize: true,
});
}
});