javascript - jQuery .data() function works when selector targets 1 element, but not when targetting multiple and iterating over them -


so i'm trying read data value of each checkbox checked, have following code:

var jobjchk = $("input:checkbox[name=resourceselect]:checked"); jobjchk.each(function () {     receivers[receivers.length] = this.data("data-email"); }); 

now when 1 checkbox checked, , use this.data, code works expected. when use code above , have multiple checkboxes selected, "i object doesn't support property or method 'data'". both should jquery objects (and supporting .data())?

your assumptions incorrect. statement:

but both should jquery objects (and supporting .data())?

is incorrect. this inside of .each() callback actual dom element, it's not jquery object. if want use jquery functions need create new jquery object containing single element:

jobjchk.each(function () {     receivers[receivers.length] = $(this).data("data-email"); }); 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -