4
I’m having problems with assigning a variable within a each in jQuery.
(function(){
var filters = $(".filter_check:checked");
var hiddenFields = '';
$.each(filters, function(){
hiddenFields += "&" + $(this).data('param') + "=1";
});
console.log( hiddenFields );
})();
On the last line, when I check the output, I see that the variable is exactly as it was declared up there, an empty string. The assignment/concatenation on . each didn’t work... That seems to me to be a problem with scope. Would someone tell me what I’m doing wrong?
Your var Filters is catching something?
– Marconi
I believe there is no checkbox/radio with the class
filter_check
selected. Your code has no problem.– Oeslei
Filters has personal yes elements... More than 10 in total.
– Pedro Vinícius
Could you post your HTML code so I can test it? I don’t understand why you’re accessing values within each with $(this). data('param').
– Marcell Alves