Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6893799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:42:13+00:00 2026-05-27T06:42:13+00:00

I trying to have a javascript function to click all divs that has an

  • 0

I trying to have a javascript function to click all divs that has an id of ‘divResults’ in my form but apparently it doesn’t work, no errors but nothing buldges. Please advice. Thanks.

 <a href="javascript:clickAllDivs()">Expand All</a>  |  <a href="javascript:clickAllDivs()" >Collapse All</a>

JavaScript :

     function clickAllDivs() {
                         var els = document.getElementsByTagName('div');
                         var i = els.length; while (i--)
                             if (els[i].id == 'divResults' ) {
                             //alert("I am in"); //Check if div is eating this function
                             els[i].click();
                         }
                     }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:42:13+00:00Added an answer on May 27, 2026 at 6:42 am

    Well there are a couple of problems, first, you should have only one element with an id of divResults in your page, ids are unique.

    To find an element with a particular id, you can do:

    var el = document.getElementById('divResults');
    

    If you want more elements, try using a class, and checking by className in your loop, like:

    while (i--) {
    if (els[i].className == 'yourClassName' ) {
         //code
       }
    }
    

    Second, calling els[i].click(); means that you have setted a property on that element with the name of click and assigned it a function.
    If you had done that, then the code is right, if not check how are you binding the event, for example if you’re doing

    document.getElementById('divResults').onclick = function(){};  //bind click event
    

    then you should do

    els[i].onclick();
    

    You can also use jQuery for doing this in a really simple way, info here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why doesn't this JavaScript work in Internet Explorer 7-8? All I am trying to
I trying to have a div with child divs that form 2 or more
I'm trying to use the replace function in JavaScript and have a question. strNewDdlVolCannRegion
I have some javascript that I'm trying to retool using jQuery to learn the
I'm trying to build something on javascript that I can have an input that
I've searched all over and have found possible solutions but they don't quite work
i know how to post data using javascript but im trying to work out
I am trying to have a javascript object tree behave like a php associative
I have a javascript code, whereby I'm trying to load a list from a
I have an external Javascript file and i am trying to alert the value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.