This my jQuery code in WordPress site. Its works well but when I run in the for-each loop its not works. I saw other answers but I can’t understand.

 jQuery(document).ready(function(){ 
             jQuery(function() {
                 jQuery('#datepicker').daterangepicker({
                     autoUpdateInput: false,
                     locale: {
                         cancelLabel: 'Cancel'
                     }
                 });
                 jQuery('#datepicker').on('apply.daterangepicker', function(ev, picker) {
                     $(this).val(picker.startDate.format('MM/DD/YYYY') + ' - ' + picker.endDate.format('MM/DD/YYYY'));
                 });
                 jQuery('#datepicker').on('cancel.daterangepicker', function(ev, picker) {
                     jQuery(this).val('');
                 });
             });

Form

<?php
foreach ($query as $row) 
    {   ?>

            <form action="">
                <div class="form-group"> 
                    <label>Check-in / Out</label>
                    <input type="text" class="form-control" id="datepicker" name="datefilter" placeholder="Check-in / Out">
                </div>
            </form>


        <?php
    }
?>  

Read more here: Daterangepicker is Not working in foreach loop


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: