jquery-data

How to remove value from FormData

独自空忆成欢 提交于 2019-11-29 03:45:20
Here is a way to append file to FormData : var data = new FormData(); jQuery.each($('#file')[0].files, function(i, file) { data.append('file-'+i, file); }); is it possible to do as below ? data[i].remove();??? or data[i] = file;?? how iIcan remove or modify a value from data You cannot do anything other than append items to a FormData object. See the Spec . It would be better if you use a dictionary/object to store all the values you want to add/modify before you actually construct the object. var data = {}; jQuery.each($('#file')[0].files, function(i, file) { data['file-'+i] = file; }); /

what does jQuery data() function do

纵饮孤独 提交于 2019-11-28 07:43:46
I have not found what is the use of jquery function data() . Can anyone give me some example of how it can be used? Doug Neiner Its really useful for associating various objects, strings, arrays, etc with a DOM element. Here is a fun hypothetical use: $(document).ready(function(){ $("a").each(function(index, el){ if(index % 2 == 0) $(this).data('coolColor', 'Orange'); // Set the data else $(this).data('coolColor', 'Purple'); // Set the data }).click(function(e){ alert($(this).data('coolColor')); // Retrieve the data e.preventDefault(); }); }); This would select every a tag, and set Orange if

Group and count HTML elements by data attribute in jQuery

泪湿孤枕 提交于 2019-11-28 03:38:52
问题 I'm trying to group each instance of a data attribute into a list from the number of occurrences of each attribute in a page, using jQuery. Similar to grouping categories or tags in a news section. For example, I would like to create something like this: Category 1 (5) Category 2 (3) Category 3 (1) from this html: <ul class="categories"> <li data-category="category-1">Category 1</li> <li data-category="category-1">Category 1</li> <li data-category="category-1">Category 1</li> <li data

Setting a value dynamically for data attributes using jquery

五迷三道 提交于 2019-11-27 22:09:30
I use data attributes extensively for managing data in client side events. Is it possible to assign value dynamically to a data attribute using javascript or jquery? <li data-class_value="somevalue" class="myclass"></li> $('.myclass').click(function(){ $(this).data('class_value') = "new value"; }); The above javascript code throws the error: "Uncaught ReferenceError: Invalid left-hand side in assignment". Could someone please tell me how this can be achieved? You need to do $(this).data('class_value', "new value"); I believe the answers above would only set the data object on that element

How to remove value from FormData

跟風遠走 提交于 2019-11-27 17:43:59
问题 Here is a way to append file to FormData : var data = new FormData(); jQuery.each($('#file')[0].files, function(i, file) { data.append('file-'+i, file); }); is it possible to do as below ? data[i].remove();??? or data[i] = file;?? how iIcan remove or modify a value from data 回答1: You cannot do anything other than append items to a FormData object. See the Spec. It would be better if you use a dictionary/object to store all the values you want to add/modify before you actually construct the

what does jQuery data() function do

一曲冷凌霜 提交于 2019-11-27 02:01:59
问题 I have not found what is the use of jquery function data() . Can anyone give me some example of how it can be used? 回答1: Its really useful for associating various objects, strings, arrays, etc with a DOM element. Here is a fun hypothetical use: $(document).ready(function(){ $("a").each(function(index, el){ if(index % 2 == 0) $(this).data('coolColor', 'Orange'); // Set the data else $(this).data('coolColor', 'Purple'); // Set the data }).click(function(e){ alert($(this).data('coolColor')); //

Where is jQuery.data() stored?

岁酱吖の 提交于 2019-11-27 01:41:25
Where does jQuery store the values of the data() that it sets to DOM objects? Is there some kind of variable like jQuery.dataDb or something, maybe even something private? Is there any way to gain access to this object? Internally, jQuery creates an empty object called $.cache , which is used to store the values you set via the data method. Each DOM element you add data to, is assigned a unique ID which is used as a key in the $.cache object. jQuery gets or sets data in 3 different ways for 3 different type of object. For DOM element, jQuery first get a unique id, than create a custom property

Where is jQuery.data() stored?

三世轮回 提交于 2019-11-26 09:46:59
问题 Where does jQuery store the values of the data() that it sets to DOM objects? Is there some kind of variable like jQuery.dataDb or something, maybe even something private? Is there any way to gain access to this object? 回答1: Internally, jQuery creates an empty object called $.cache , which is used to store the values you set via the data method. Each DOM element you add data to, is assigned a unique ID which is used as a key in the $.cache object. 回答2: jQuery gets or sets data in 3 different

jquery get HTML 5 Data Attributes with hyphens and Case Sensitivity

孤人 提交于 2019-11-26 03:56:40
问题 How to get data attributes using jquery .data()? In which case html5 data-* attributes converts to lowercase and camelcase? What are all the main rules to follow while using custom attributes to store data? <input type=\"button\" class=\"myButton\" value=\"click me\" data-productId=\"abc\"/> <input type=\"button\" class=\"myButton\" value=\"click me\" data-product-id=\"abc\"/> <input type=\"button\" class=\"myButton\" value=\"click me\" data-PRODUCT-ID=\"abc\"/> <input type=\"button\" class=\