Reputation: 354
I don't know what the hell is going on.
Why isn't my simple javascript code working? Been here for hours. I have a bunch of other javascript, was thinking if it's interrupting or something?
Trying to through a tutorial, then I got stuck at the first line:
$('#name').keyup(function() {
alert('alert');
});
I don't know the problem.. in fiddle it's all working of course http://jsfiddle.net/pgWtK/1/
I tried putting it inside the head with document ready but that doesn't help so, any clues?
Upvotes: 3
Views: 261
Reputation: 35973
The problem is in the file vote.js
change the code wth this code you have miss $(
$(document).ready(function(){
$(function(){
$('#name').keyup(function() {
alert('alert');
});
});
})
Upvotes: 0
Reputation: 148130
You need to put it in $(document).ready(function(){
so that the DOM elements are available to jquery before use, in your case element with id name for binding keyup event.
Also make sure you have included jquery tag.
This article will guide you how to use jquery.
$(document).ready(function(){
$('#name').keyup(function() {
alert('alert');
});
})
Upvotes: 4
Reputation: 31033
wrap up your code inside the document ready
$(function(){
//your code
});
in jsfiddle it done by default but if you select the no-wrap(head)
option it would not wrap your js code inside the ready
handler see it for yourself.
It's always a good practice to place your js code inside the ready
handler so that it is ensured before all the js glitter happens the DOM is rendered, or you can place the js script at the end of your markup
Upvotes: 0
Reputation: 7783
$(document).ready(...)
callUse the following code in your console of FiregBug or alternative to make sure that the event has been bound to the element:
$('#name').data('events');
Upvotes: 2
Reputation: 2150
Two things might happen, you dont have correctly loaded Jquery Library or you have not putted that code inside document ready
add jquery in your head example:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
jquery inside document ready
$(function(){
$('#name').keyup(function() {
alert('alert');
});
});
Upvotes: 2