Reputation: 7105
I have a button on one of my views
<div class="span12">
<button id="saveButton" class="btn"><i class="icon-download-alt green"></i> Save</button>
</div>
and a JQuery click event
$("#saveButton").click(function () {
alert("Save clicked");
});
For some reason the click event is never triggered. If I place an alert before the JQuery event the alert is triggered successfully.
I'm sure I'm missing something really simple here, but I cant seem to find the problem.
I made sure that
Is there any reason why this event is not triggered?
Upvotes: 0
Views: 225
Reputation: 2917
Here is the working code,
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.0.min.js"></script>
<script>
$(document).ready(function(){
$("#saveButton").click(function () {
alert("Save clicked");
});
});
</script>
</head>
<body>
<div class="span12">
<button id="saveButton" class="btn"><i class="icon-download-alt green"></i> Save</button>
</div>
</body>
</html>
Upvotes: 0
Reputation: 305
$(function() {
$("#saveButton").click(function () {
alert("Save ");
});
});
hope this will works
Upvotes: 0
Reputation: 2500
please check working fiddle here :
$( document ).ready(function() {
$("#saveButton").click(function () {
alert("Save clicked");
});
});
Upvotes: 0
Reputation: 4870
Try this:
$( document ).ready(function() {
$("#saveButton").click(function () {
alert("Save clicked");
});
});
Upvotes: 3
Reputation: 337714
You need to put your code in a document ready handler. Without it jQuery will attempt to attach the click
event before the element exists in the DOM.
$(function() {
$("#saveButton").click(function () {
alert("Save clicked");
});
});
Upvotes: 4