Ivan Vulović Ivan Vulović - 5 months ago 10
jQuery Question

Document.ready won't work

Any idea why this code doesn't work ? I defined a text input field with this ID in the HTML.

$('document').ready(function()
{
$('#inputUsername').keyup(alert("something"));
}
);

Answer

keyup takes a function:

$('#inputUsername').keyup(function() {
    alert("something")
});

Or, define the function before hand:

function clickHandler(event) {
    alert("something");
}

And pass it in:

$('#inputUsername').keyup(clickHandler)

And unquote document -- it's its own variable.