0

I have this div in my view index.php:

<div id="lightgallery-<?php echo get_the_ID(); ?>">
</div>

In my load-data.php i have this:

foreach($subpages as $post) : setup_postdata($post);
    <div id="lightgallery-<?php echo get_the_ID(); ?>">
    <?php
        foreach ($files as $image) {
            $image_attributes = wp_get_attachment_url( $image->ID );
            $attachment_title = get_the_title($image->ID);
            $caption = get_post_field('post_excerpt', $image->ID);
            ?>
          <a class="item" href="<?php echo $image_attributes ?>"  data-sub-html="<?php echo $attachment_title; ?> <?php if($caption!= '') echo ' - ' ?> <?php echo $caption ?>"><img src="<?php echo $image_attributes ?>"></a>
         <?php }
endforeach ?>
       </div>

In my script i have this:

$(".open").click(function (e) {
                    var id = $(this).find('.get_id').text()
                    e.preventDefault();
                    $.ajax({url: "/load-data", success: function(result){
                        var data = $(result).find('data').html()
                        console.log(result);
                         $("#lightgallery-"+id).html(data);
                            $('#lightgallery-'+ id + ' .item:first').click();
                 }});

Now what i want is when user click on link to send id to load-data.php and get specific div from foreach with that id. Any suggestion how can i do that. With my script right now i get all data from first and from second foreach, i want just from second foreach but for that specific id.

EDIT: I tried this but its undefined.

var div = $('#lightgallery-' +id, $(result)).html();
None
  • 8,817
  • 26
  • 96
  • 171

0 Answers0