Answer the question
In order to leave comments, you need to log in
How to generate json array by selector?
Please tell me how to generate an array of several json objects, which is the src attribute for images with a certain class, i.e. all to be generated into an array of type$('.detail-image-fancy').attr('src')
[
{href : 'src'},
{href : 'src'},
{href : 'src'},
]
Answer the question
In order to leave comments, you need to log in
var urls = [];
$('.detail-image-fancy').each(function () {
var src = $(this).prop('src');
urls.push({href: src});
});
var json = JSON.stringify(urls);
//Псевдомассив jQuery
var data = $.map($('.detail-image-fancy'), function(e){
return {href : e.src};
});
//Нормальный массив
var data = [].map.call($('.detail-image-fancy'), function(e){
return {href : e.src};
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question