Hudson Atwell
Hudson Atwell

Reputation: 192

JQuery: Get SRC for each image that has specific atrtibute

I am wokring on a dialog, where in execution I want to round up all items that have a specific attribute and place an attribute value of their's into a comma delited list.

This is as far as I have gotten, which isnt far.

buttons: {       

'Hook': function(){ $('.grid_pic:has(border=3)').(loop through id's, grab src, build variable with srcs comma delimeited)

}

Any ideas?

Upvotes: 0

Views: 306

Answers (2)

Nick Craver
Nick Craver

Reputation: 630379

This is a concise approach to getting it:

var commalist = $('.grid_pic:has(border=3)').map(function() { 
                  return $(this).attr('src');
                }).get().join(',');

Upvotes: 0

David Morton
David Morton

Reputation: 16505

var srcs = new Array();

$('.grid_pic[border=3]').each(function() { 
    srcs[srcs.length] = $(this).attr('src');
});

var result = srcs.join(',');

Upvotes: 1

Related Questions