1

I need to catch click event in jquery and this is my HTML code:

<input type="button" id="aggiungiDomande" value="+">

and this is my Jquery code:

$('#aggiungiDomande').on('click',function(){
alert("HI");
});

I think I'm wroing something because I show nothing. Anyone can help me?

2
  • It is working fine. If you didn't put your code in $(document).ready(function() { //code } See jsfiddle.net/harishkommuri/yb4yp29z Commented Mar 14, 2016 at 15:30
  • Have you wrapped your javascript code into $(document).ready()? Commented Mar 14, 2016 at 15:31

2 Answers 2

1
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>


<script>
$("document").ready(function(){
$('#aggiungiDomande').on('click',function(){
alert("HI");
});
});

</script>
</head>
<body>

<button id = "aggiungiDomande">Click me</button><br><br>

</body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

0

You could try something like this :

$(document).on('click', '#aggiungiDomande',function(){
    alert("HI");
});

If your button does not exist when your code is executed, no event wil get bound to it. You can read more about event binding here : http://api.jquery.com/on/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.