Skip to content Skip to sidebar Skip to footer

Set Value Of Input Element With Jquery

I am trying to change the value of the inputfields with JQuery and I have no idea why this doesn't work. It does not throw an error but it just doesn't change. I'm building with ap

Solution 1:

Make sure that your code is running after the DOM is loaded.

Also there is no need for jQuery in your example.

You can just do:

window.onload = function(){
    document.getElementById("url").value = 'test';
};

Demo: http://jsfiddle.net/qwertynl/7uCfc/


And if you want to do full on jQuery:

$(function(){
    $('#url').val('test');
});

Demo: http://jsfiddle.net/qwertynl/m5Ttn/


Or you could not wrap your code in an onload and just put the whole script at the end of the document after the page has loaded already.


Post a Comment for "Set Value Of Input Element With Jquery"