On a HTML page i have an input with a value attribute which is changed by some library i use. After the user changes the value of the input the value property is changed.
After some action i want to remove the user provided value property and let the input show the value provided by the attribute again, and from that point on, do that automatically (like it did before the user ever entered a value).
I looked at some other questions like What is the difference between properties and attributes in HTML? . They all give a descent explanation ofthe difference between property and attribute however nothing to remove the user filled property.
Things i have tried (with jQuery in FF):
$("#my-input").removeProp('value'); // This has no effect
$("#my-input").prop('value', null); // Makes the input empty
$("#my-input").prop('value', false); // Sets value to the string "false"
$("#my-input").prop('value', undefined); // Makes the input empty
$("#my-input").prop('value', $("#my-input").attr('value')); // Sets the correct value however if the external library changes the attribute it doesn't change the prop with it
Edit 1
As requested i made a small minimal snippet showing the question better: https://jsfiddle.net/codx3vmg/
Edit 2
I managed to find a snippet which does exactly what i desire with a form: https://jsfiddle.net/9h6py8oc/
However, in my case i do not have my inputs in a form. Can i reset a specific input (without a form)?
$("#my-input").val('')? Not sure if you are saying you want to remove thevalueattribute entirely or just empty it. Can you show what this input looks like with both the property and attribute you mention in your question?$("#my-input").val('')will set the content of the input to nothing. Not the value of the value attribute...val()to get/set the value of an input, there's nothing more to it. If you want to track other stuff, use other attributes, egdata-attributes are commonly used for this. I'm guessing that doesn't help, if so, please edit your question and try to create a minimal, complete, and verifiable example showing what you're having trouble with.formelement, appending the input, callingreset()on the form, then appending the input back to its original location and discarding the form element?