Link to home
Start Free TrialLog in
Avatar of ambuli
ambuliFlag for United States of America

asked on

Iterate through all divs within a div

Hi there,
I need to iterate through a Div which contains other divs.
I want to find all the ones with ID that starts with "ReportDataDivID".  The following code works, but I am iterating via all the DOM.  I want to just go over the testDiv which will be passed to this function. How can I efficiently do this.  Thank you.


var __ensureVisible = function(testDiv){
        var divs = document.getElementsByTagName("div");
        for(var i = 0; i < divs.length; i++){
            var regexp = new RegExp('^' + "ReportDataDivID");
            if(regexp.test(divs[i].id)){
                $("#" + divs[i].id).show();
            }
        }
    };

Open in new window

SOLUTION
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ambuli

ASKER

Thank you very much for your answer.  It works great.  Can you please let me know where can I see the documentation for the jquery select API.  Thank you.
Hi,

the main jQuery API is here:
http://api.jquery.com/

Further selector choices:
http://api.jquery.com/category/selectors/attribute-selectors/

Thanks for the points
Rainer