help me get the value from the button, I can not
my code:
<a href="" onclick="funk(this)" value="123" class="price-button"><i class="fas fa-shopping-cart"></i> press</a>
<script>
funk = (a) => {
console.log(a.value)
}
</script>
2
Answers
Set a value in
HTML
and retrieve it on click withgetAttribute
There’s a few issues in your code:
a
elements don’t have avalue
attribute. Use adata
attribute to add custom metadata to an elementonclick
attributesHere’s a corrected version using plain JS:
And the same thing in jQuery, as you tagged that as well: