I have a button which has an ID, on click of the button I need to match the ID of the button with the documents data-id attribute and then add a class to the respective element.
this.$('.add-resource').click(function() {
var testId = $(this).attr('id');
alert(testId);
$('#layoutCanvas').find("[data-id='" + testId + "']").addClass('hidden');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a class="btn btn-primary add-resource" id="567">Button</a>
<div id="layoutCanvas">
<div data-id="567">
Test 1
</div>
<div data-id="235">
Test 2
</div>
</div>