I want to show the jQuery datepicker on click of a FontAwesome icon which is inside the input field. Below is the code:
<div class="col-md-4 col-sm-4 col-xs-12">
<label for="datepicker">Date of birth*</label>
<input type="text" name='datepicker' class="form-control" value="Select date" id="datepicker" ng-required="true" placeholder="MM/DD/YYYY" >
<span class="fa fa-calendar"></span>
</div>
jQuery('.fa-calendar').on('click' , function() {
jQuery(this).datepicker().trigger('focus');
});
You can use the
'open'
setting on a datepicker to programmatically open it. There's no need to trigger afocus
event. You also need to call thedatepicker()
method on the#datepicker
element, not the clicked icon. Try this:HTML
JS
This is what you want to do. It will work, you can fill date in your input type like below.
You want to trigger the datepicker on the input box, not the icon, so you need to change
to be
Try this
Here is the example