lafrog lafrog - 7 days ago 6
jQuery Question

Jquery button() click event doesnt work

i cant find my mistake.
alert() is definitely working, but not inside $('#submit1').click function...



$(document).ready(function(){
$('#submit1').click(function(){
alert("JQuery Running!");
});
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Jquery Basic</title>
</head>
<body>
<a>JQuery Test Page</a><br>
<input id="#submit1" type="button" value="Submit"/>
</body>
</html>




M.M M.M
Answer

You are not supposed to put the # in the html, only in the jquery selector. So just change

<input id="#submit1" type="button" value="Submit"/>

to

<input id="submit1" type="button" value="Submit"/>

Snippet:

$(document).ready(function(){
    $('#submit1').click(function(){
        alert("JQuery Running!");
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>Jquery Basic</title>
    </head>
    <body>
        <a>JQuery Test Page</a><br>
        <input id="submit1" type="button" value="Submit"/>
    </body>
</html>