Search code examples
javascriptjqueryajaxlaravel-5.3

jQuery class selection Confusion


<div id="entry{{$allpdt->id}}" class="entry value">
    <span>{{$value}}</span>
</div>

How can I call this div ID using jQuery?

I am using Laravel 5.4.

 $(document).ready(function (e) {
     var ids = $('#ids').val();
     $(document).on('click','#entry+ids', function(){
     });
});

I Tried this but it won't work.


Solution

  • Either use an existing class or attach a static class just for the purpose of selecting these elements.

    HTML:

    <div id="entry{{$allpdt->id}}" class="entry value myjQuerySelectorClass">...</div>
    

    jQuery:

    $('.myjQuerySelectorClass').on('click', function(){
        var currentID = $(this).attr('id');
    });
    

    I used an on-click case but you can apply it to your specific situation.