-1

This is my function I'm trying to get button's value and display HTML for every element correctly but when I do a click on my button I have this error.

function prueba() {
    var value = $("button").val();
    alert(value);
}

This is my button

var btnbp1 = document.createElement('button');
btnbp1.value = '0';
btnbp1.setAttribute('onclick', 'selection()');
btnbp1.className = 'windowprimarybutton';
var btnBp1Img = document.createElement('img');
btnBp1Img.src= 'images/bp1.jpg';
btnbp1.appendChild(btnBp1Img);
divButtonsConteiner.appendChild(btnbp1);

enter image description here

Dev
  • 1,592
  • 2
  • 22
  • 45

1 Answers1

0
<button id="btn" value="Mybtn">Click</button>

<script>

    $(document).ready(function () {

        $("#btn").click(function () {

            var btnval = $(this).val();

            $('p').text(btnval);
        });
    });

</script>
Abhishek Gurjar
  • 7,426
  • 10
  • 37
  • 45
Vin Jivani
  • 19
  • 3