dimanche 31 décembre 2017

How to get dynamic value inside loop using jquery in laravel

Always get the same id. I want to get the dynamic value in the p tag Id attribute that comes from the foreach loop every time the new id change. I want that id when I click on Read More.

<div class="carousel-inner">

    @foreach($news as $new)
      <div style="display:none" class="newsID" id=""></div>
      <div  class="item">
         <h2></h2>                          
      </div>
    @endforeach

   <p><a href="javascript:;" id="readmore-btn"  class="read-more">Read More</a></p>
</div>

Below is the jQuery code:

<script>
        $(document).on('click','.read-more',function(){

             $(this).closest('.carousel-inner').attr('id','tempID');

            var data  = $('#tempID .newsID').attr('id');

            alert(data);
            $('#tempID').removeAttr('id');
        });    

</script>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire