javascript for locating divs and finding the ids in each

I am looking to find all DIV's on a page, find the id and be able to construct a javascript call based on the results.

This is just an idea... Im open to suggestions...

<div class="AdbinControl_ID" id="2240"></div> (top banner)
<div class="AdbinControl_ID" id="2241"></div> (side banner)
<div class="AdbinControl_ID" id="2242"></div> (left corner)
<div class="AdbinControl_ID" id="2242"></div> (right corner)

var x = document.getElementsByClassName("AdbinControl_ID");
var i;
for (i = 0; i < x.length; i++) {
    get the id's ... add to var... 2240, 2241, 2242[0], 2240[1]
Do the call to get the ads, then loop to replace
for (i = 0; i < x.length; i++) {    
   document.getElementById('2240').innerHTML = result [1]

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Russ SuterSenior Software DeveloperCommented:
If you're not using jQuery (which you should look into) then use the document.getElementsByTagName() method to find all <div> elements on your page. That would replace your call to document.getElementsByClassName() but it now means you aren't relying on a class to find your divs.
Julian HansenCommented:
Two methods for getting the ID's - plain JavaScript and jQuery
  var els = document.getElementsByClassName('AdbinControl_ID');
  var ids = [];
  for(var i = 0; i < els.length; i++) {
    ids[i] = els[i].id;
$(function() {
  // jQuery Way
  var ids = [];
  $('.AdbinControl_ID').each(function(i) {
    ids[i] = $(this).attr('id');

Open in new window

Output is identical for both
 ["2240", "2241", "2242", "2242"]

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
amakaramAuthor Commented:
Good point Russ.
Julian, this is the right direction!
Let me review
Russ SuterSenior Software DeveloperCommented:
Have you reviewed? Do you still need assistance?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.