jQuery attr() vs prop()

Difference between attr() and prop() methods in jquery

by Bipen Chhetri

HTML

<input type="text" value="test" id="test"/>

JavaScript

//you would use val() for input text. but this is just and example to show how attr() and prop() actaully works

// alert on document load to check the value of input using attr() and prop()
alert('attr(): '+$('#test').attr('value'));
alert('prop(): '+$('#test').prop('value'));

//change the input text value and click outside the input.
$('#test').change(function(){
    alert('attr(): '+$(this).attr('value'));
    alert('prop(): '+$(this).prop('value'));
});