If you store a value in jQuery.data()
$('#customerName').data('cname','test');
then postback the page will the value in .data() be available when the page reloads?
Thanks
If you store a value in jQuery.data()
$('#customerName').data('cname','test');
then postback the page will the value in .data() be available when the page reloads?
Thanks
no it won't, just like all other JavaScript client-side. You could persist data on the client using cookies.
Working Demo to demonstrate
code
$(function() {
$('#store').click(function() {
$.data(document, "value", "This is the value stored in data");
$('#data').text('Stored!').css('background-color', 'red');
});
$('#get').click(function() {
$('#data').text($.data(document, "value")).css('background-color', 'green');
});
$('#clear').click(function() {
$('#data').text('');;
});
});
It shouldn't be as you can't keep javascript state when you reloading the page. At least not in the easy way.
No. The data is attached to the DOM element - which is lost when the page reloads. Understanding the difference between the page source and the DOM is the key.
It would be very, very bad if the browser actually kept track of which data is attached to which element, and subsequently tried to match it to elements on the reloaded page.
However, what is it that you are trying to achieve? In most, if not all, cases, there is an alternative solution.