I wonder – do I need to use ready events like $(document).ready() in jQuery for DOM manipulation. For example, I have a javascript function:
function handler(input,id) {
$(document).ready(function(){
document.getElementById(input).value = id;
document.search_form.submit();
});
}
A couple of comments regarding your code :
Line 2 and 5 are not needed – since this is a function and will be called rather than execute on load you don’t need the ready handler. The
$(document).ready(function() {line means execute the following code when theDOMisready– if its inside a function like yours is its not needed (but will still work). You can read more aboutready()hereLine 3 can be changed to
$('#'+input).val(id);this uses the jQuery ID selector and theval()function to change the value.Ending up with
You could probably change your code a little more judging by the function name ….