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
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
you set data-value as a class. that cant work
<div class="remove-btn data-value = 1">
should be <div class="remove-btn" data-value="1">
okk
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
write it like jochem did.
class and data-* are two separate attributes
you wrote the data-value inside class=""
<div class="remove-btn" data-value="${index}">
ok. THankyou