Link to home
Start Free TrialLog in
Avatar of Adrian Cross
Adrian Cross

asked on

Delete only the children divs from a parent div

Hi, I'm trying to delete all the children divs that I created dynamically in a parent div. The parent div contains different controls, not just divs.

 var imgContainer = document.getElementById("ContentPlaceHolder1_div_Container");
    var childDivs = imgContainer.getElementsByTagName("div");

    var NumberOfDivs = childDivs.length;

    for (i = 0; i < NumberOfDivs; i++) {
        imgContainer.removeChild(childDivs[i]);
    }

Open in new window


If there is only one child div, the code works fine. However, when I append multiple divs I get the following error

"JavaScript runtime error: No such interface supported"

Any ideas?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe 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
Avatar of Adrian Cross
Adrian Cross

ASKER

Excellent! Many thanks!