X'Byte X'Byte - 7 months ago 20
Javascript Question

Alert user with selection from bootstrap button

Following this JSFiddle, I'm trying to alert() the user of his selection after he selects a button from the 'likert scale'.

https://jsfiddle.net/taxvkvu9/

Trying something like:

$(".btn btn-default").click(function () {
alert(event.relatedTarget.textContent);
})


however it does not seem to be working. What am I missing?

Answer

You need to add a period and remove the space

$(".btn.btn-default").click(function () {
  alert($(this).text()); /* this alerts the text content of the button */
});