Data Attributes on INPUT tags

Okay, first off, are the HTML 5 data attributes allowed on input tags? Every example I see, shows them on non-form related tags.

The reason I ask, is jquery doesn’t return the data attribute value of my form elements as shown here

I should note that using

$('input:first').attr('data-originalValue');

does retrieve the value

If you’re wanting the default value of the input field, that is a property, not an attribute. The property is called defaultValue.

So in that case, you could use something like:


$('input:first').prop('defaultValue');

Unfortunately, that doesn’t seem to work for checkboxes/radio buttons. Regardless of the status (checked/unchecked), it returns the value. That does seem to work fine for text fields.

Nevermind, I just saw I am to use defaultChecked instead of defaultValue on radio/checkboxes. prop should work, so long as I can update the value

The defaultValue isn’t used with checkboxes or radio buttons. It’s a text field that is just not suitable for those types of fields.

The jQuery prop() documentation page says that there is a defaultChecked property though, which seem like a much better candidate for your intended usage.