I have the following problem
<a href='#' data-entry-id='{{ income.incSum }}' id='some_link_1'></a>
const $entryElements = $('[data-entry-id]');
const $entryIds =
$.map($entryElements, item => $(item).data('entryId'));
console.log("entry ids ", $entryIds);
If the data-entry-id attribute is in square brackets, everything works, the values are displayed.
Only I would like to get to the value of the data-entry-id attribute whose id is some_link_1 (because I have several data-entry-id values on the page):
<a href="#" data-entry-id="{{ income.incSum }}" id="some_link_1"></a>
I use the following notation for this:
const $entryElements2 = $('#some_link_1').attr('[data-entry-id]');
const $entryIdsEle = $.map($entryElements2, item => $(item).data('entryId'));
console.log("mine is: ", $entryIdsEle);
If data-entry-id is in square brackets, the values are empty, but if it is without brackets:
const $entryElements2 = $('#some_link_1').attr('data-entry-id');
an error occurs
Please help me how I could get to this data using attribute and id name.
I used this article https://cruftlesscraft.com/passing-data-from-twig-to-javascript
2
Answers
try something like this, that work for me