1

here is my a class Button in html, inside you can find the id with one value group_name. But I need to pass another variable $group_search_overview->groupsid to jquery.

@foreach($groups_search_overview as $group_search_overview)
            <a class="btn btn-primary btn-block test_uebergabe" id="{{$group_search_overview->group_name}}">                   
                {{$group_search_overview->group_name}}
            </a>
@endforeach

This is my jquery script

$(document).on('click', '.test_uebergabe', function () {
                var idgroups = $(this).attr("id");
                $('.modal-body').html(idgroups);
                $('#dataModal').modal({show: true});  
});

How can I send a second variable to jquery? What's the correct way to do this?

Thanks.

1
  • 3
    To save custom data to html element you can use the data attribute, to access these with jQuery use .data() Commented Jul 16, 2018 at 12:16

1 Answer 1

0

Just add a data attribute:

<a data-group="{{your variable here}} class="btn btn-primary btn-block test_uebergabe" id="{{$group_search_overview->group_name}}"">

Than in jquery:

let group = $(this).data('group');

where this would be the currently focussed button.

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

Comments