Try attaching a keyup
event handler
This will fire when ever the user releases the key.
$('#search').keyup(function() {
console.log(this.value)
}).change();
If you want to fire the same on document ready then you can just chain the event after the declaration.
$(document).ready(function () {
$('#search').keyup(function () {
//reddit API URL
//var URL = "http://www.reddit.com/r/subreddits/search.json?q=Xbox";
var SEARCH_URL = 'http://www.reddit.com/r/subreddits/search.json?jsonp=?';
var searchQueryText = this.value; // or $(this).val(()
$.getJSON(SEARCH_URL, {
q: searchQueryText,
limit: 10
}).done(function (data) {
$.each(data.data.children, function (i, item) {
$("<p>").text(item.data.title).appendTo("#images");
});
}).fail(function (data) {
alert("Something went wrong");
});
}).keyup();
}); //end ready