<button type="button" data-value="100" id="btn">BUTTON</button>
const btnVal = $("#btn").data("value");
console.log(typeof btnVal); -- "btnVal" type is number
I want to get the value as a string, but is there any other way to use toString()?
Just read it as an attribute. like this:
const btnVal = $("#btn").attr("data-value");
console.log(typeof btnVal);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
<button type="button" data-value="100" id="btn">BUTTON</button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With