issues with Data-attribues.

so im trying to get value of a data attribute. After clicking on a button a function runs where the console.log(value) gives
<div class="remove-btn data-value = 1">
<svg>
<use href="icons.svg#IcOutlineAdd"></use>
</svg>
</div>
<div class="remove-btn data-value = 1">
<svg>
<use href="icons.svg#IcOutlineAdd"></use>
</svg>
</div>
so i updated the code to console.log(value.getAttribute("data-value")) to get the value of data attribute, instead of giving me 1 its giving null . Anyone know how to fix this?
6 Replies
CodeNascher
CodeNascher2y ago
you set data-value as a class. that cant work
Jochem
Jochem2y ago
<div class="remove-btn data-value = 1"> should be <div class="remove-btn" data-value="1">
Avinash
AvinashOP2y ago
okk
<div class="remove-btn data-value = ${index}">
<svg>
<use href="icons.svg#IcOutlineAdd"></use>
</svg>
</div>
<div class="remove-btn data-value = ${index}">
<svg>
<use href="icons.svg#IcOutlineAdd"></use>
</svg>
</div>
this is how ilooped via js. what should i do so that its not in the class? i gave outside the class still its was inside
CodeNascher
CodeNascher2y ago
write it like jochem did. class and data-* are two separate attributes you wrote the data-value inside class=""
Jochem
Jochem2y ago
<div class="remove-btn" data-value="${index}">
Avinash
AvinashOP2y ago
ok. THankyou thumbup
Want results from more Discord servers?
Add your server