I've been told that this: var g = $.grep($('div').get(), function (item) { return /^#rating/.test(item.hash); }); var panelIds = $.map(g, function (item) { return item.hash }).join("', '"); document.write(return item.hash); Code (markup): will get all the ids of div elements where the id begins with "rating" and echo them like '#rating1', '#rating2', '#rating3' However I'm getting nothing. What I want is to put var panelIds into this, replacing the .stars and .rating, etc classes: $('.stars').mouseover(function (){ var star = $(this).index() + 1; $(this).parent().css("background-position","0 -" + (32 * star) + "px"); }); $(panelIds).mouseout(function (){ $(this).css("background-position","0 -" + <?=$done32?> + "px"); }); $('.stars').click(function (){ var id = $(this).parent().attr('id').split('rating')[1]; var vote = $(this).parent().attr('name').split('result')[1]; $.ajax({ type: "POST", url: "http://www.airwalk-design.com/community/herotozero/backend-rate.php", data: "id=" + id + "&vote=" + vote }); $(this).parent().removeAttr("id"); $(this).parent().html(" "); $('.vote-done').fadeIn('slow', function() { doBlink(".vote-done"); }); }); Code (markup): The reason that I'm doing this is because all the ids of these divs are dynamically fetched from php, however they do all begin with "rating", which I why I wanted to get them with javascript, will this even work?
I'm not really good with jQuery, but I can tell you this should work: var div = document.getElementsByTagName("div"); var rating; for(i=0;i<=div.length;i++){ if(div[i] && div[i].id.match(/rating/i)){ if(rating){ rating += ", "+div[i].id; }else{ rating = div[i].id; } } } document.write(rating); Code (markup):