JQuery.data and dynamically changing HTML5 user attributes

Problem:

JQuery html5 objects custom DATA attributes are cached.
In my application, I have a form with a field that has a variable attribute of user data, and this specific behavior is required for a functionally form.


What we have here:

There is an input field with a specific user-defined attribute by default:

<input type="text" name="xxx" data-test="4">


Get custom attribute

for the $('input').data()result will be{ test="4" }


change own attribute

$('input').attr('data-test','5')


Get custom attribute - again

for the $('input').data()result will be STILL be{ test="4" }


Question

REAL, , $.data()? $.removeData() , , .

+5
1

: $('input').data( 'test' , 5 )

.attr( 'test' , 5 ), , : <input type='text' data-test='4' test='5' />

, : var test = $('input').data('test');

: jQuery.removeData( $( 'input' ) , "test" );

+7

All Articles