0

my button doesn't work when I click on it nothing happens. This is my HTML for it:

<form id="myform" name="myform" action="senden.php" method="get">
        <ul><div>
                <li>
            <button id="testbutton" name="testbutton" value="abgesendet2" type="button">test</button>

            <p> Felder mit einem Stern müssen ausgefüllt werden! </p>
        </ul>

    </form>

and this is my jQuery for it (the button is in a form):

<script> 
        jQuery('document').ready(function(){

            $("#myform").on('click', '#testbutton', function(){
                alert("test");
            });

        });
    </script>
Mr. Robot
  • 1
  • 2

2 Answers2

1

You only need to make a small change. Attach the click directly to the target button and it will work.

$('document').ready(function(){
    $("#testbutton").on('click', function(){
        alert("test");
    });
 });


 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="testbutton" name="testbutton" value="abgesendet2" type="button">test</button>
Manuel Cheța
  • 480
  • 2
  • 10
0

Your code seems working correctly, are you sure you were including jquery? Here is what I tested:

<script src="http://code.jquery.com/jquery-latest.min.js"
    type="text/javascript"></script>

<script> 
    jQuery('document').ready(function(){

        $("#myform").on('click', '#testbutton', function(){
            alert("test");
        });

    });
</script>   


<form id="myform" name="myform" action="senden.php" method="get">
<ul><div>
    <li>
        <button id="testbutton" name="testbutton" value="abgesendet2" type="button">test</button>

        <p> Felder mit einem Stern müssen ausgefüllt werden! </p>
    </ul>

</form>

Here is a jsfiddle too. Do it works?