Click here to Skip to main content
13,093,720 members (61,204 online)
Rate this:
Please Sign up or sign in to vote.
How do I get to add all links within a particular div from vb browser?

I'm trying to get all links from the div class linksmain.


<div class="linksmain">
<a href="">Image</a>
<a href="">Image</a>
<a href="">Image</a>

So far I've got this..


Dim web As New WebBrowser
If web.ReadyState = WebBrowserReadyState.Complete Then
    Dim allelements As HtmlElementCollection = web.Document.All
    For Each webpageelement As HtmlElement In allelements
End If
Posted 30-Apr-13 3:31am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

That's client side stuff - you would use javascript for that. Here's a javascript function that will return an array containing the IDs of all the elements (that have IDs) in the chosen div. You'll have to enumerate them and decide which children you need to use. This means that all the items you are looking for must have IDs, of course.

   function GetAllChildrenIn(parentElement) {
            var children = new Array();
            var numFound = 0;
            try {
                var obj = document.getElementById(parentElement);
                var numChildren = obj.childNodes.length;
            } catch (e) {
                alert('Error setting vars. (' + e.Message + ')'); }
            try {
                for (var count = 0; count < numChildren; count++) {
                    if (obj.childNodes[count].id) {
                        children[numFound] = obj.childNodes[count].id;
            } catch (e) { alert('Error enumerating children. (' + e.Message + ')'); }
            return children;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100