It's a late answer but now there is an easy way. Current version of jquery lets you search if attribute exists. For example
$('[id]')
will give you all the elements if they have id. If you want all spans with id starting with span
you can use
$('span[id^="span"]')