In a web page we have an input type text:
<input id="bar" type="text" />
I want to insert before another input element before the above element:
var input = $('<input type="text" value="foo" id="ciccia" />')
input.insertBefore($('#bar'))
And add a simple behavior:
input.on('keyup', function(){
console.log(input.attr('value'));
})
console.log always get "foo" string
If I change
var input = $('<input type="text" value="foo" id="ciccia" />')
to
var input = $('<input type="text" value="bar" id="ciccia" />')
console.log always get "bar" string.
What's wrong with DOM? Why I cannot read the real value of text input?