Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What can cause jquery.data() disappearing?

Tags:

jquery

I'm having trouble with jQuery element.data() resetting mysteriously. I've checked that the data is stored ok to the element on a click event.

Some simple tests to recreate the problem (with no success) here.

What happens after the data-storing is a series of actions, changing id:s for the data-fields, form submit, handling of the response, some rendering etc... In short, enough things that it's slow to find the problem. I've checked the $.cache-object which doesn't have the data I stored. The .removeData's in the code all target the submit-button in the form where I edit the input-fields.

$element.removeData('attribute'); 

Any ideas what things can cause the data to reset?

jQuery.data source here

like image 580
Marcus Avatar asked Nov 14 '22 15:11

Marcus


1 Answers

Jquery data also gets removed from an element when the element gets removed from the DOM. You can still access the deleted element inside a mutation observer, but the Jquery data on it is gone.

like image 67
Nick Avatar answered Jan 09 '23 08:01

Nick