Getting value of a class
This question already has an answer here:
- JQuery get the title of a button 6 answers
Why can i get an id value with # but cant get a class value with .
ex:
$(button#${value}
).val() --> works
$(button.${value}
).val() --> doesn't work.
Answers 1
When your
button
element does not have avalue
property,val()
will return the empty string.But if you put a
value
attribute to yourbutton
element it works, as this snippet demonstrates:Or, if you take for instance the button's text (
.text()
), then also it works: