Answer the question
In order to leave comments, you need to log in
How to iterate through all elements with the same class, select their texts and add them to one variable separated by commas?
Hello! How to iterate through all elements with the same class in jQuery, select their texts and add them to one variable separated by commas?
For example, there is a structure like this:
<td class="model">456</td>
<td class="model">443</td>
<td class="model">12</td>
var models = "456,443,12";
document.cookie = "models ="+models+"; path=/";
$('body').on('click','#button-confirm',function(){
var models = '';
$("td.model").each(function(){
models = $(this).html() + ',';
console.log(models);
document.cookie = "models="+models+"; path=/"; // библиотека для сохранения в куки
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question