Why doesn\'
$('selector').attr('id')
will return the id of the first matched element. Reference.
If your matched set contains more than one element, you can use the conventional .each
iterator to return an array containing each of the ids:
var retval = []
$('selector').each(function(){
retval.push($(this).attr('id'))
})
return retval
Or, if you're willing to get a little grittier, you can avoid the wrapper and use the .map
shortcut.
return $('.selector').map(function(index,dom){return dom.id})