Changing the input value does not affect firebug

Just try changing the input value with jQuery. It seems to work, however, when I look at the #input value using Firebug, it remains in the original value. Is this normal, or am I doing something wrong? Thanks you

http://jsfiddle.net/tsfSg/

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /> 
<title>Testing</title> 
<script src="http://code.jquery.com/jquery-latest.js"></script> 
<script> 

$(function(){
    $("#DoIt").click(function()
    {
        $('#input').val('final');
        console.log($('#input'));
        alert($('#input').val());
    });
});

</script>
</head>

<body>
<a href="#" id="DoIt">DoIt</a>
<input id="input" type="text" value="original" />
</body> 
</html>
+3
source share
1 answer

Use .val():console.log( $('#input').val() );

$(function(){
    $("#DoIt").click(function(){
        $('#input').val('final');
        console.log($('#input').val());  // the fixed line!
        alert($('#input').val());
    });
});

demo


EDIT

Now I understand what you are looking at: inside the source of an element (verification element) in Firebug.
Well, if you want the changes to really happen, you have to use:

$('#input').attr('value','final');

instead:

$('#input').val('final');

otherwise, the change is stored by the browser (fear nothing), but Firebug is not updated.

in this demo you can see it working:

demonstration

$("#DoIt").click(function(e){
    $('#input').attr('value','final');     // use .attr() to see the change happen in Firebug!
    // $('#input').val('final');           //  but rather use this
    // $('#input').prop('value','final');  // or better THIS one!
    console.log( $('#input').val() );
    alert( $('#input').val() );
    return false;
});
+5
source

All Articles