最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get ID of all divs with a class on a page - jquery - Stack Overflow

programmeradmin3浏览0评论

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.

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.

Share Improve this question edited May 23, 2013 at 6:11 Robin Maben 23.1k16 gold badges68 silver badges99 bronze badges asked Sep 4, 2012 at 17:45 Jacob WindsorJacob Windsor 6,9906 gold badges35 silver badges49 bronze badges 1
  • I'm unable to think of a good reason why you'd want to do this. Can't you just use an ordinary HTML form? – Blazemonger Commented Sep 4, 2012 at 17:47
Add a ment  | 

2 Answers 2

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

DEMO

Put the data in a array

 Var ids= new Array();
 $('.newsItem').each(function(){
            ids[] = $(this).attr('id');
    });
发布评论

评论列表(0)

  1. 暂无评论