I simply want to get the current value of a field’s attribute.
This field has a default value like:
<input validation="defaultValue" />
When i want to get the validation attribute, i don’t know if it has been updated before or if this is still the default value.
So the property get with prop() return undefined when the property is not set (not yet updated), and the attr() method return always the default value (that’s not true actually for maintainability but that will be in the future).
Is there a method that check:
if property is set => return property
else return attribute
Thanks
This snippet will do:
Explanation:
typeof ... "undefined", the"prop"string returns. Otherwise, the"attr"string returns.inputobject, eitherinput["prop"](=input.prop) orinput["attr"](=input.attr)."validation"as an argument, resulting in:I recommend to use
data-validationinstead ofvalidation, to be HTML5-compliant.Update: A JQuery method: