1

I need to get the ID of every div with a class and send it across to another PHP file. I would assume I need all of the ID's in one variable. The ID's will be put into a mysql query where I will find data that does not equal these ID's. How can this be done?

I have tried jQuery's each function but you cannot put all of the data from that function into one variable. At least not the way i did it.

This is what i've tried.

$('.newsItem').each(function(){
     alert (this.id);
});

Thanks in advance.

Robin Maben
  • 19,662
  • 16
  • 61
  • 93
Jacob Windsor
  • 6,162
  • 6
  • 30
  • 47

2 Answers2

13
var ids = $('.className').map(function(){
   return this.id;
}).get();

DEMO

pimvdb
  • 141,012
  • 68
  • 291
  • 345
Robin Maben
  • 19,662
  • 16
  • 61
  • 93
0

Put the data in a array

 Var ids= new Array();
 $('.newsItem').each(function(){
            ids[] = $(this).attr('id');
    });
jtheman
  • 7,211
  • 3
  • 24
  • 38