简体   繁体   中英

jQuery data() cleared when drag and drop

I have a contenteditable container with some images inserted. Also I have defined some internal values to these images with the jQuery.data() function.
Everything is working well untill I move these images inside the contenteditable. Then, all data associated with the images is gone.
Do you know how to avoid this? or if there is a better solution to assign information to DOM elements?

I used to assign values to DOM elements within their data- attributes.

So instead of data() , i'd use

set: $('image').attr('data-attr1', 'value1');
get: $('image').attr('data-attr1');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM