1

I have html code like this :

<td class="fc-day fc-widget-content fc-sun fc-past" data-date="2016-07-17"></td>
<td class="fc-day fc-widget-content fc-mon fc-past" data-date="2016-07-18"></td>

I want to append html if the data-date come's in between startdate and enddate.

$(document).ready(function(){
    var d = $(".fc-day").data('date');
    $.ajax({
        url : '<?php echo base_url()."admin/utilities/get_task_assign_staff" ?>',
        dataType : 'json',
        success : function(responce){               
            $(".fc-day").each(function(){
                var d = $(".fc-day").data('date');
                if(d == responce[0].startdate)
                {
                    this.append("<span class='fc-title'>"+responce[0].name+"</span>");
                }
            });
        }
    });
});

For Example, my startdate is 2016-07-05 and enddate is 2016-07-09 than append responce[0].name to the given <td> that data-date come's in between startdate and enddate.

So what jQuery should I have to write?

1 Answer 1

1
$(document).ready(function(){
  $.ajax({
    url : '<?php echo base_url()."admin/utilities/get_task_assign_staff" ?>',
    dataType : 'json',
    success : function(responce){      
        $('.fc-day').each(function(){
            var data_date = $(this).attr('data-date'),
               response = $.parseJSON(responce);
            if(data_date == response.startdate){
                $(this).html("<span class='fc-title'>"+response.name+"</span>");
            }
        });
      }
   });
});
  1. You want to get the attribute date_date from the elements that contain the class fc-day. This is how you get this attribute.

    $('.fc-day').each(function(){var data_date = $(this).attr('data-date');});

  2. You have indicated that you expecting JSON as response, so you want to probably use parseJSON for the responce you got.

I hope i helped to solve your issue. Cheers

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.